Spatial predator-prey simulation

Spatial distribution of rabbits

\(\(\(
\)\(\(r0\  = \ 100;\)

    \(rabbits\  = 
Table[{Random[], Random[]}, {i, 1, 
            r0}];\)


    \(plot[
          rabbits_]\  := 
ListPlot[
rabbits, 
Prolog -> 
            PointSize[0.015], 
PlotRange -> 
            All, 
Axes -> 
            False, 
AspectRatio -> 
            Automatic, 
DisplayFunction -> 
            Identity
];\)


    \(Show[
plot[
          rabbits], 
DisplayFunction -> $DisplayFunction
];\)




    \)\)\)

Moving the rabbits

δ  =  0.01;
step[{x_, y_}] := 
{Mod[
            x + δ* Cos[2  π * Random[]], 
            1], 
Mod[
            y + δ* Sin[2  π * Random[]], 
            1]
};
move[list_]  :=  
Map[step, 
          list];

    
T  =  100;
t  =  1;
While[
        t < T, 
rabbits  =  
          move[rabbits]; 
Show[
plot[
            rabbits], 
DisplayFunction -> $DisplayFunction
]; 
t  =  
          t + 1
];

Creating new rabbits

pbirth  =  0.03;
create[
          rabbits_]  := 
Module[{newrabbits}, 
newrabbits  =  
            rabbits; 
Do[
If[
              Random[] < pbirth, 
AppendTo[newrabbits, 
                rabbits[[i]]]
], 
{i, 
              1, Length[
                rabbits]}
]; 
newrabbits
];

    
rabbits  = 
Table[{Random[], Random[]}, {i, 1, 
            r0}];
rabbitcount  = {{0, r0}};
t  =  0;
While[
        t < T, 
rabbits  =  
          move[rabbits]; 
rabbits  =  
          create[rabbits]; 
Show[
plot[
            rabbits], 
DisplayFunction -> $DisplayFunction
]; 
t  =  
          t + 1; 
AppendTo[
          rabbitcount, {t, 
            Length[rabbits]}]
];

Plotting the population of rabbits

point  =  
        Graphics[{PointSize[0.00001], 
            Point[{0, 0}]}];
rcountplot  = 
ListPlot[
rabbitcount, 
PlotJoined -> 
            True, 
DisplayFunction -> 
            Identity
];
\(\(Show[
point, 
        rcountplot, 
Prolog -> {PointSize[0.015], 
            Thickness[0.005]}, 
Axes -> 
          True, 
AxesStyle\  -> \ {Thickness[
              0.005]}, 
AxesOrigin -> {0, 
            0}, 
TextStyle -> {FontWeight -> "Bold", 
            FontSize -> 
              18}, 
AxesLabel -> {"t", "pop"}, 
PlotRange -> 
          All, 
DisplayFunction -> $DisplayFunction
];\)



\)

Introducting foxes that eat the rabbits

δ  =  0.05;
step[{x_, y_}] := 
{Mod[
            x + δ* Cos[2  π * Random[]], 
            1], 
Mod[
            y + δ* Sin[2  π * Random[]], 
            1]
};
move[list_]  :=  
Map[step, 
          list];

    
pbirth  =  0.03;
create[
          rabbits_]  := 
Module[{newrabbits}, 
newrabbits  =  
            rabbits; 
Do[
If[
              Random[] < pbirth, 
AppendTo[newrabbits, 
                rabbits[[i]]]
], 
{i, 
              1, Length[
                rabbits]}
]; 
newrabbits
];

    
r0  =  100;
rabbits  = 
Table[{Random[], Random[]}, {i, 1, 
            r0}];

    
f0  =  
      30;   (*10;*) 
foxes  = 
Table[{Random[], Random[]}, {i, 1, 
          f0}];

plotred[
          foxes_]  := 
ListPlot[
foxes, 
PlotStyle -> 
            RGBColor[1, 0, 0], 
Prolog -> 
            PointSize[0.015], 
PlotRange -> 
            All, 
Axes -> 
            False, 
AspectRatio -> 
            Automatic, 
DisplayFunction -> 
            Identity
];


distance[{x1_, y1_}, {x2_, y2_}]  := 
Module[{x, 
            y}, 
x  =  
            Min[{Abs[x1 - x2], Abs[x1 - x2 + 1], 
                Abs[x1 - x2 - 1]}]; 
y  =  
            Min[{Abs[y1 - y2], Abs[y1 - y2 + 1], 
                Abs[y1 - y2 - 1]}]; 
Sqrt[
            x^2  +  y^2]
];

    
peaten  =  1;   
pdeath  =  
      0.05;   (*0.05;*) 

ϵ =  0.025;
eat[rabbits_, 
          foxes_]  := 
Module[{newrabbits, newfoxes, i, j, 
            hungry}, 
newrabbits  =  
            rabbits; 
newfoxes  =  {}; 
Do[
hungry  =  
              True; 
j  =  1; 
While[
              j ≤ Length[newrabbits]  &&  
                hungry, 
If[
                distance[foxes[[i]], 
                      newrabbits[[j]]] < ϵ  &&  
                  Random[] < peaten, 
newrabbits  =  
                  Delete[newrabbits, j]; 
AppendTo[
                  newfoxes, foxes[[i]]]; 
hungry  =  
                  False
]; 
j  =  
                j + 1
]; 
If[
              Random[] >  pdeath, 
AppendTo[newfoxes, 
                foxes[[i]]]
], 
{i, 
              1, Length[
                foxes]}
]; 
{newrabbits, 
            newfoxes}
];

    
rabbitcount  =  {{0, r0}};
foxcount  =  {{0, f0}};
T  =  500;
t = 0;
While[
        t < T  &&  Length[rabbits] >  0  &&  
          Length[foxes] >  0, 
rabbits  =  
          move[rabbits]; 
foxes  =  
          move[foxes]; 
{rabbits, foxes}  =  
          eat[rabbits, foxes]; 
rabbits  =  
          create[rabbits]; 
If[
          Length[rabbits] > 0  &&  
            Length[foxes] > 
              0, 
Show[
plot[
              rabbits], 
plotred[
              foxes], 
DisplayFunction -> $DisplayFunction
]
]; 
t  =  t  + 1; 
AppendTo[
          rabbitcount, {t, Length[rabbits]}]; 
AppendTo[
          foxcount, {t, 
            Length[foxes]}]
];

Plotting the populations of rabbits and foxes

point  =  
        Graphics[{PointSize[0.00001], 
            Point[{0, 0}]}];
rcountplot  = 
ListPlot[
rabbitcount, 
PlotJoined -> 
            True, 
DisplayFunction -> 
            Identity
];
fcountplot  = 
ListPlot[
foxcount, 
PlotStyle -> 
            RGBColor[1, 0, 0], 
PlotJoined -> 
            True, 
DisplayFunction -> 
            Identity
];
\(\(\(Show[
point, rcountplot, 
        fcountplot, 
Prolog -> {PointSize[0.015], 
            Thickness[0.005]}, 
Axes -> 
          True, 
AxesStyle\  -> \ {Thickness[
              0.005]}, 
AxesOrigin -> {0, 
            0}, 
TextStyle -> {FontWeight -> "Bold", 
            FontSize -> 
              18}, 
AxesLabel -> {"t", "pop"}, 
PlotRange -> 
          All, 
DisplayFunction -> $DisplayFunction
];\)\(
\)
    \)\)