#include#include #include #include #include #include #include #include struct Fish { int NumBumps; int NumCol; int Row; int Col; int Turns; bool Produced; int TurnsSince; apstring Facing; }; struct Egg { int Row; int Col; }; apvector Fishies; int TurnsBetweenMating; int YouthTime; int Lifetime; bool Search(int, int); void Clear(apmatrix &); void ProcessEgg(apmatrix , apvector &, int, apvector &Fishies); void SetEggs(apmatrix &, int, int); void DeadFish(int Subscript); void DeadEgg(apvector &, int Subscript); void Set(apmatrix &, int, int, apstring); void Display(apmatrix ); void Decide(apmatrix , int &, int &, apstring &, int &, int &, apvector &, bool &, int &, int &, int &); void main() { apvector Eggs; apstring Lines; int NumLines=0; ifstream Parameters("fish.ini"); int Rows, Cols; for(int Aha=0; Aha<5; Aha++) { getline(Parameters, Lines); } Parameters>>Rows>>Cols>>TurnsBetweenMating>>YouthTime>>Lifetime; apmatrix Matrix(Rows, Cols, " "); while(!Parameters.eof()) { getline(Parameters, Lines); NumLines++; } Fishies.resize(NumLines/3); Parameters.close(); Parameters.open("fish.ini"); for(int Bleck=0; Bleck<10; Bleck++) { getline(Parameters, Lines); } for(int Num=0; Num >Fishies[Num].Row>>Fishies[Num].Col>>Fishies[Num].Facing; Fishies[Num].NumCol=0; Fishies[Num].NumBumps=0; Fishies[Num].Turns=0; Fishies[Num].TurnsSince=3; } //Parameters>>Row>>Col>>Facing>>Row2>>Col2>>Facing2; while(1) { if(Fishies.length()==0) { exit(0); } Clear(Matrix); for(Num=0; Num Matrix, apvector &Eggs, int Sub, apvector &Fishies) { if(Eggs[Sub].Row==Matrix.numrows()-1) { Fishies.resize(Fishies.length()+1); Fishies[Fishies.length()-1].Row=Matrix.numrows()-1; Fishies[Fishies.length()-1].Col=Eggs[Sub].Col; Fishies[Fishies.length()-1].Facing="Down"; Fishies[Fishies.length()-1].NumBumps=0; Fishies[Fishies.length()-1].NumCol=0; Fishies[Fishies.length()-1].Turns=0; Fishies[Fishies.length()-1].TurnsSince=5; DeadEgg(Eggs, Sub); } else { Eggs[Sub].Row++; } } void DeadEgg(apvector &Eggs, int Subscript) { for( ; Subscript &Matrix, int Row, int Col) { Matrix[Row][Col]="*"; } void DeadFish(int Subscript) { for( ; Subscript &Fishies, int Subscript) { for( ; Subscript &Matrix) { for(int Blank=0; Blank &Matrix, int Row, int Col, apstring Facing) { if(Facing=="Up") { Matrix[Row][Col]="^"; } else if(Facing=="Down") { Matrix[Row][Col]="V"; } else if(Facing=="Left") { Matrix[Row][Col]="<"; } else { Matrix[Row][Col]=">"; } } void Display(apmatrix Matrix) { for(int Blah=0; Blah TurnsBetweenMating) { Blah=true; Fishies[Bleck].TurnsSince=0; } } return Blah; } void Decide(apmatrix Matrix, int &Row, int &Col, apstring &Facing, int &NumCol, int &NumBumps, apvector &Eggs, bool &Mated, int &Turns, int &I, int &TurnsSince) { RandGen Random; Mated=false; bool Done=false; Random.RandInt(1, 100); int Choice; if(++Turns==Lifetime) { DeadFish(I); Done=true; } TurnsSince++; while(Done==false) { Choice=Random.RandInt(1, 9); switch(Choice) { case 1:if(Row>0&&Col>0) { if(Matrix[Row-1][Col-1]==" ") { Row-=1; Col-=1; Facing="Left"; Done=true; } else if(Mated==false&&Turns>YouthTime&&TurnsSince>TurnsBetweenMating) { bool Go; Go=Search(Row-1, Col-1); if(Go==true) { NumCol++; Eggs.resize(Eggs.length()+1); Eggs[Eggs.length()-1].Row=Row; Eggs[Eggs.length()-1].Col=Col; Mated=true; } } } else { NumBumps+=1; } break; case 2:if(Row>0) { if(Matrix[Row-1][Col]==" ") { Row-=1; Facing="Up"; Done=true; } else if(Mated==false&&Turns>YouthTime&&TurnsSince>TurnsBetweenMating) { bool Go; Go=Search(Row-1, Col); if(Go==true) { NumCol+=1; Mated=true; Eggs.resize(Eggs.length()+1); Eggs[Eggs.length()-1].Row=Row; Eggs[Eggs.length()-1].Col=Col; } } } else { NumBumps+=1; } break; case 3:if(Row>0&&Col YouthTime&&TurnsSince>TurnsBetweenMating) { bool Go; Go=Search(Row-1, Col+1); if(Go==true) { NumCol+=1; Mated=true; Eggs.resize(Eggs.length()+1); Eggs[Eggs.length()-1].Row=Row; Eggs[Eggs.length()-1].Col=Col; } } } else { NumBumps+=1; } break; case 4:if(Col>0) { if(Matrix[Row][Col-1]==" ") { Col-=1; Facing="Left"; Done=true; } else if(Mated==false&&Turns>YouthTime&&TurnsSince>TurnsBetweenMating) { bool Go; Go=Search(Row, Col-1); if(Go==true) { NumCol+=1; Mated=true; Eggs.resize(Eggs.length()+1); Eggs[Eggs.length()-1].Row=Row; Eggs[Eggs.length()-1].Col=Col; } } } else { NumBumps+=1; } break; case 5:if(Facing=="Up") { Facing="Down"; } if(Facing=="Down") { Facing="Up"; } if(Facing=="Right") { Facing="Left"; } if(Facing=="Left") { Facing="Right"; } Done=true; break; case 6:if(Col YouthTime&&TurnsSince>TurnsBetweenMating) { bool Go; Go=Search(Row, Col+1); if(Go==true) { NumCol+=1; Mated=true; Eggs.resize(Eggs.length()+1); Eggs[Eggs.length()-1].Row=Row; Eggs[Eggs.length()-1].Col=Col; } } } else { NumBumps+=1; } break; case 7:if(Col>0&&Row YouthTime&&TurnsSince>TurnsBetweenMating) { bool Go; Go=Search(Row+1, Col-1); if(Go==true) { NumCol+=1; Mated =true; Eggs.resize(Eggs.length()+1); Eggs[Eggs.length()-1].Row=Row; Eggs[Eggs.length()-1].Col=Col; } } } else { NumBumps+=1; } break; case 8:if(Row YouthTime&&TurnsSince>TurnsBetweenMating) { bool Go; Go=Search(Row+1, Col); if(Go==true) { NumCol+=1; Mated=true; Eggs.resize(Eggs.length()+1); Eggs[Eggs.length()-1].Row=Row; Eggs[Eggs.length()-1].Col=Col; } } } else { NumBumps+=1; } break; case 9:if(Col YouthTime&&TurnsSince>TurnsBetweenMating) { bool Go; Go=Search(Row+1, Col+1); if(Go==true) { NumCol+=1; Mated=true; Eggs.resize(Eggs.length()+1); Eggs[Eggs.length()-1].Row=Row; Eggs[Eggs.length()-1].Col=Col; } } } else { NumBumps+=1; } break; } } }
Text file Source (historic): geocities.com/thepastavandal
(to report bad content: archivehelp @ gmail)
|
|
|
|
|