Beispiel #1
0
		static byte RunGame(Virus virus, Agent p1, Agent p2) {
			Move move;
			byte winner;

			while (true) {
				move = p1.Move(virus);
				virus.Move(move.sx, move.sy, move.ex, move.ey);
				winner = virus.Winner;
				if (winner != 0)
					break;
				move = p2.Move(virus);
				virus.Move(move.sx, move.sy, move.ex, move.ey);
				winner = virus.Winner;
				if (winner != 0)
					break;
			}
			p1.EndGame(virus);
			p2.EndGame(virus);
			return winner;
		}
Beispiel #2
0
		static void TestGame() {
			bool testresult = false;
			Virus virus = new Virus();
			ShowBoard(virus);

			testresult = ShouldCrashTest(() => virus.Move(0, 4, 0, 4)); //moving starting player's piece to it's own position
			ShowResult("Test 1", testresult);
			testresult = ShouldCrashTest(() => virus.Move(0, 4, 0, 1)); //moving starting player's piece too far
			ShowResult("Test 2", testresult);
			testresult = ShouldCrashTest(() => virus.Move(0, 0, 0, 1)); //moving non-starting player's piece
			ShowResult("Test 3", testresult);
			testresult = ShouldCrashTest(() => virus.Move(0, 0, 0, 3)); //moving non-starting player's piece too far
			ShowResult("Test 4", testresult);

			Console.WriteLine("The game should be in the start state:");
			ShowBoard(virus);

			Console.WriteLine("Making a move:\nThis should move the top left piece one space SE");
			virus.Move(0, 4, 1, 3);
			ShowBoard(virus);

			testresult = virus.Winner == 0; //there shouldn't be a winner yet
			ShowResult("Test winner", testresult);
			testresult = ShouldCrashTest(() => virus.Move(1, 3, 0, 2)); //moving player 1's piece again
			ShowResult("Test own piece", testresult);
			testresult = ShouldCrashTest(() => virus.Move(0, 0, 0, 3)); //moving player 2's piece too far
			ShowResult("Test opponent's piece", testresult);

			Console.WriteLine("Making a move:\nThis should move the bottom left piece one space N");
			virus.Move(0, 0, 0, 1);
			ShowBoard(virus);

			testresult = virus.Winner == 0; //there shouldn't be a winner yet
			ShowResult("Test winner", testresult);
			testresult = ShouldCrashTest(() => virus.Move(0, 4, 3, 0)); //moving player 1's piece too far
			ShowResult("Test own piece", testresult);
			testresult = ShouldCrashTest(() => virus.Move(0, 0, 0, 2)); //moving player 2's piece again
			ShowResult("Test opponent's piece", testresult);

			Console.WriteLine("Making a move:\nThis should move the piece at (1,3) two spaces S\n and take the adjacent pieces");
			virus.Move(1, 3, 1, 1);
			ShowBoard(virus);

			testresult = virus.Winner == 0; //there shouldn't be a winner yet
			ShowResult("Test winner", testresult);
			testresult = ShouldCrashTest(() => virus.Move(1, 1, 1, 0)); //moving player 1's piece again
			ShowResult("Test own piece", testresult);
			testresult = ShouldCrashTest(() => virus.Move(4, 4, 1, 0)); //moving player 2's piece too far
			ShowResult("Test opponent's piece", testresult);
		}