public PersonChat() { InitializeComponent(); profileImage.Source = new BitmapImage(new Uri("pack://application:,,,/Resources/notFound2.png")); profileChatNumber.Content = personChatId; contextMenuDataGrid.Opened += contextMenuDataGrid_Opened; datagrid.ContextMenu = contextMenuDataGrid; sm = new SmartBot(this); }
public void SmartbotGenerateChoiceTest(PlaysEnum oldPlay, PlaysEnum newPlay) { //Arrange SmartBot bot = new SmartBot(); bot.callback.Invoke(oldPlay, PlaysEnum.Paper, GameResults.Undecided); //Act var botNextPlay = bot.Play(); //Assert Assert.AreEqual(newPlay, botNextPlay); }
private static void SelectPlayers(ref Player player1, ref Player player2) { Console.WriteLine("Select player 1"); Console.WriteLine("\t H - Human Player; R - Random Bot; S - SmartBot: "); var choice1 = Console.ReadLine(); Console.WriteLine("Select player 2"); Console.WriteLine("\t H - Human Player; R - Random Bot; S - SmartBot;"); var choice2 = Console.ReadLine(); switch (choice1.ToUpper()) { case "H": player1 = new HumanPlayer(); break; case "R": player1 = new RandomBot(); break; case "S": player1 = new SmartBot(); break; default: player1 = null; break; } switch (choice2.ToUpper()) { case "H": player2 = new HumanPlayer(); break; case "R": player2 = new RandomBot(); break; case "S": player2 = new SmartBot(); break; default: player2 = null; break; } }
public void Minimax_Xwin() { var boardString = "X.X|XXX|.XX|OXX|O..|OOO|OXO|..O|.OO|OXX|OOO|XOO|XXX|OX.|.XX|.O.|O..|OO.|O..|OOO|.OX|XXX|...|...|..O|XXO|XXX"; var macroboard = "AXO|XOA|XOX"; var bot = new SmartBot(); var state = new BotState(); state.Field.MyId = 0; state.UltimateBoard.ParseFromString(boardString); state.UltimateBoard.ParseMacroboardFromString(macroboard); // X should be placed in top-left microboard so X wins macroboard on vert left Move move = bot.GetMove(state); // More moves available in center-right of microboard Assert.IsTrue(move.X == 1 && move.Y == 0, "Actual move is " + move); }
public void Minimax_Owin() { var boardString = "X.O|OO.|.XX|OXX|O..|OOO|OXO|..O|.OO|OXX|OOO|XOO|XXX|OX.|.XX|.O.|O..|OO.|O..|OOO|.OX|XXX|...|...|..O|XXO|XXX"; var macroboard = "AXO|XO.|XOX"; var bot = new SmartBot(); var state = new BotState(); state.Field.MyId = 0; state.UltimateBoard.ParseFromString(boardString); state.UltimateBoard.ParseMacroboardFromString(macroboard); // X should be placed in top-left microboard since it's the only spot // open, then O should win top-middle microboard to win macroboard vert middle Move move = bot.GetMove(state); // More moves available in center-right of microboard Assert.IsTrue(move.X == 1 && move.Y == 0, "Actual move is " + move); }
public void GetMove_FirstMoveBlankBoard() { var boardString = "...|...|...|...|...|...|...|...|...|...|...|...|...|...|...|...|...|...|...|...|...|...|...|...|...|...|..."; var macroboard = "AAA|AAA|AAA"; var bot = new SmartBot(); var state = new BotState(); state.Field.MyId = 1; state.UltimateBoard.ParseFromString(boardString); state.UltimateBoard.ParseMacroboardFromString(macroboard); Console.Write(state.UltimateBoard); Move move = bot.GetMove(state); // X moved to row 6 and col 7 Assert.IsTrue(move.X == 1 && move.Y == 0 && move.Score == 0, "Actual move is " + move + " and score = " + move.Score); }
public void Minimax_XWin() { var boardString = "OOO|OO.|.XX|OXX|O..|OOO|OXO|..O|.OO|OXX|OOO|.OO|XXX|OX.|OXX|.O.|O..|OXO|XOO|XXX|O.O|X.X|...|OXX|O.X|XXO|XXO"; var macroboard = "OOX|TOX|AXA"; var bot = new SmartBot(); var state = new BotState(); state.Field.MyId = 0; state.UltimateBoard.ParseFromString(boardString); state.UltimateBoard.ParseMacroboardFromString(macroboard); Console.Write(state.UltimateBoard); Move move = bot.GetMove(state); // X wins Assert.IsTrue(move.X == 7 && move.Y == 6 && move.Score == 100, "Actual move is " + move + " and score = " + move.Score); }
public void Minimax_Xwin2() { var boardString = "OOO|OO.|.XX|OXX|O..|OOO|OXO|..O|.OO|OXX|OOO|.OO|XXX|OX.|OXX|.O.|O..|OXO|XOO|XXX|O.O|XX.|...|OX.|O.X|XXO|XXO"; var macroboard = "OOX|TO.|AX."; var bot = new SmartBot(); var state = new BotState(); state.Field.MyId = 0; state.UltimateBoard.ParseFromString(boardString); state.UltimateBoard.ParseMacroboardFromString(macroboard); Console.Write(state.UltimateBoard); // X should be placed in [2,7] to win [0,2] microboard Move move = bot.GetMove(state); // More moves available in center-right of microboard Assert.IsTrue(move.X == 2 && move.Y == 7, "Actual move is " + move); }
public void Minimax_XLose2() { var boardString = "OOO|OO.|.XX|OXX|O..|OOO|OXO|..O|.OO|OXX|OOO|.OO|XXX|OX.|OXX|.O.|O..|OXO|XOO|XXX|O.O|X.X|...|OXX|O.X|XXO|XXO"; var macroboard = "OOX|TOA|.X."; var bot = new SmartBot(); var state = new BotState(); state.Field.MyId = 0; state.UltimateBoard.ParseFromString(boardString); state.UltimateBoard.ParseMacroboardFromString(macroboard); Console.Write(state.UltimateBoard); // X can't win, so [1,7] is chosen first Move move = bot.GetMove(state); // X loses Assert.IsTrue(move.X == 6 && move.Y == 3 && move.Score == -100, "Actual move is " + move + " and score = " + move.Score); }
private List <Player> SetPlayers() { List <Player> plrs = new List <Player>(); bool chooseAnother = true; while (chooseAnother) { Console.WriteLine("Choose the type of Player you want to add: "); switch (Console.ReadLine()) { case "human": Console.Write("Enter the name: "); string name = Console.ReadLine(); Console.Write("Choose a letter as Symbol: "); string symbol = Console.ReadLine(); Player newGuy = new HumanPlayer(name, symbol); //name and symbol in constructor of human player or here? plrs.Add(newGuy); break; case "rndBot": Player newRnd = new RandomBot(); plrs.Add(newGuy); break; case "Bot": Player newBot = new SmartBot(); plrs.Add(newGuy); break; case "s": chooseAnother = false; break; default: Console.WriteLine("1 for human Player - 2 for random Bot - 3 for smart Bot - s to start the Game"); break; } } return(plrs); }
/* IBot bot1 = new DynamiteBot.Program(); * IBot bot2 = new ProgramGeneral(3); * TestBots(bot1, bot2);*/ public static int TestBots(SmartBot bot1, IBot bot2, bool output = true) { Gamestate game1 = new Gamestate(); Gamestate game2 = new Gamestate(); List <Round> rounds1 = new List <Round>(); List <Round> rounds2 = new List <Round>(); int bot1D = 100; int bot2D = 100; int bot1Wins = 0; int bot2Wins = 0; int value = 1; for (int i = 0; i < 2500; i++) { game1.SetRounds(rounds1.ToArray()); game2.SetRounds(rounds2.ToArray()); Move move1, move2; try { move1 = bot1.MakeMove(game1); } catch (Exception e) { if (output) { Console.WriteLine($"Bot1 error, Bot2 wins, score was {bot1Wins} - {bot2Wins}"); } Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); return(-1); } try { move2 = bot2.MakeMove(game2); } catch (Exception e) { if (output) { Console.WriteLine($"Bot2 error, Bot1 wins, score was {bot1Wins} - {bot2Wins}"); } Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); return(1); } if (move1 == Move.D && bot1D-- == 0) { if (output) { Console.WriteLine($"Bot1 out of dynamite, Bot2 wins, score was {bot1Wins} - {bot2Wins}"); } return(-1); } if (move2 == Move.D && bot2D-- == 0) { if (output) { Console.WriteLine($"Bot2 out of dynamite, Bot1 wins, score was {bot1Wins} - {bot2Wins}"); } return(1); } var round1 = new Round(); var round2 = new Round(); round1.SetP1(move1); round1.SetP2(move2); round2.SetP1(move2); round2.SetP2(move1); rounds1.Add(round1); rounds2.Add(round2); var result = Utils.GetScore(move1, move2); if (result == 0) { value++; } else { if (result > 0) { bot1Wins += result * value; } else { bot2Wins -= result * value; } value = 1; } if (bot1Wins >= 1000) { if (output) { Console.WriteLine($"Bot1 wins, score was {bot1Wins} - {bot2Wins}"); } return(1); } else if (bot2Wins >= 1000) { if (output) { Console.WriteLine($"Bot2 wins, score was {bot1Wins} - {bot2Wins}"); } return(-1); } } if (output) { Console.WriteLine($"Draw, score was {bot1Wins} - {bot2Wins}"); } return(0); }
public SmartBot2Window() { InitializeComponent(); sm = new SmartBot(null); loaded(); }