public static SquareValues PlayBots(GameBoard Board, BotPlayer Bot, BotPlayer Bot2) { BotPlayer BlackBot = null; BotPlayer WhiteBot = null; int turn = 1; Board.InitialiseEmptyBoard(); Board.InitializePieces(); bool cont = true; if (Bot.Type == SquareValues.Black) { BlackBot = Bot; WhiteBot = Bot2; } else { BlackBot = Bot2; WhiteBot = Bot; } while (!Board.GameIsWon() && cont == true) { if (turn == 1) { BlackBot.Move(); if (Board.GameIsWon()) { cont = false; turn = 1; return(BlackBot.Type); } if (!Board.CanMove(Board.OpponentType(BlackBot.Type)) && !Board.GameIsWon()) { cont = false; turn = 1; return(BlackBot.Type); } turn = 2; } if (turn == 2) { WhiteBot.Move(); if (Board.GameIsWon()) { cont = false; turn = 1; return(WhiteBot.Type); } if (!Board.CanMove(Board.OpponentType(WhiteBot.Type)) && !Board.GameIsWon()) { cont = false; turn = 1; return(WhiteBot.Type); } turn = 1; } } turn = 1; return(SquareValues.Empty); }
/// <summary> /// Simulates a game with 2 given Bots and returns the winner in terms of the player number /// </summary> /// <param name="board"></param> /// <param name="Bot"></param> /// <param name="Bot2"></param> /// <returns></returns> public static int PlayBots(GameBoard board, BotPlayer Bot, BotPlayer Bot2) { int turn = 1; board.InitialiseEmptyBoard(); board.InitializePieces(); bool cont = true; while (!board.GameIsWon() && cont == true) { if (turn == 1) { Bot.Move(); if (board.GameIsWon()) { cont = false; turn = 1; return(1); } if (!board.CanMove(SquareValues.White) && !board.GameIsWon()) { cont = false; turn = 1; return(1); } turn = 2; } if (turn == 2) { Bot2.Move(); if (board.GameIsWon()) { cont = false; turn = 1; return(2); } if (!board.CanMove(SquareValues.Black) && !board.GameIsWon()) { cont = false; turn = 1; return(2); } turn = 1; } } turn = 1; return(0); }