public override AMove ChooseMove(AMove[] options, Board b, Form1 f, Player[] players, int depth) { this.form = f; b.PrintBoard2(f); // AMove ans; int f1 = 0, f2 = 0, t1 = 0, t2 = 0; string[] from, to; form.printMessageGui("Please enter your next move"); while (form.getMoveIsClicked() == false) { } if (form.getMoveIsClicked() == true) { form.setMoveIsClicked(false); from = form.getTextBox1().Split(' '); try { f1 = int.Parse(from[0]); f2 = int.Parse(from[1]); to = form.getTextBox2().Split(' '); t1 = int.Parse(to[0]); t2 = int.Parse(to[1]); } catch (Exception invalid_input) { Console.WriteLine("invalid input"); ans = new AMove(-1, -1, -1, -1); //this move is guarenteed to fire the ilegal move catcher in game master return(ans); } form.clearTextBox(); while (f1 == null || f2 == null || t1 == null || t2 == null || f1 < 0 || f1 > 7 && f2 < 0 || f2 > 7 && t1 < 0 || t1 > 7 && t2 < 0 || t2 > 7) { form.printMessageGui("Please enter a valid move!"); if (form.getMoveIsClicked() == true) { form.printMessageGui(" "); form.setMoveIsClicked(false); from = form.getTextBox1().Split(' '); f1 = int.Parse(from[0]); f2 = int.Parse(from[1]); to = form.getTextBox2().Split(' '); t1 = int.Parse(to[0]); t2 = int.Parse(to[1]); form.clearTextBox(); } } //System.Threading.Thread.Sleep(1000); } ans = new AMove(f1, f2, t1, t2); //ans = stored; //stored = null; return(ans); }
public void tmpp(Player p1, Player p2) { b = new Board(); b.PrintBoard2(f); player1 = p1; player2 = p2; player1.color = 1; player1.direction = 1; player2.color = 2; player2.direction = -1; Player[] players = { p1, p2 }; Player ans; turn = 1; }
public Player PvP(Player p1, Player p2, bool human) { Console.WriteLine("game start!"); b = new Board(); b.PrintBoard2(f); player1 = p1; player2 = p2; player1.color = 1; player1.direction = 1; player2.color = 2; player2.direction = -1; int logInd = 0; // Player[] players = { p1, p2 }; turn = rnd.Next(2); while (logInd < 150) //max moves { AMove[] MA = GetAllMoves(b, players[turn]); AMove m = players[turn].ChooseMove(MA, b, f, players, 3); while (MA != null && m != null && !IsLegalMove(b, m, players[turn])) { //will only shoot in case of human player making an illegal move if (m.From[0] == -1 && m.From[1] == -1 && m.To[0] == -1 && m.To[1] == -1) { f.printMessageGui("Please fill all fields with valid input"); } else { f.printMessageGui("the move " + m.From[0] + "," + m.From[1] + " to " + m.To[0] + "," + m.To[1] + " isn't legal."); } Thread.Sleep(2000); //give the human player time to read the messege if (human) //there is a human player in the game { m = players[turn].ChooseMove(GetAllMoves(b, players[turn]), b, f, players, 5); //the AI thinks 5 moves ahead } else { m = players[turn].ChooseMove(GetAllMoves(b, players[turn]), b, f, players, 3); //the AI thinks 3 moves ahead } } if (m == null) //the player currently playing has no legal move to make. win condition { f.printMessageGui("player " + (Math.Abs(turn - 1) + 1) + " is the winner! "); b.PrintBoard2(f); //Console.WriteLine("Total moves: " + logInd); Console.WriteLine("Player " + Math.Abs(turn - 1) + " is the winner!"); return(players[Math.Abs(turn - 1)]); //return the player who hasent lost } /* * if (logInd > 100 && b.QueenRatio(players[turn], b) == 1.0 && b.SoldierRatio(players[turn], b)==1.0) //soft tie condition * { * return null; * } */ PerformMove(b, m, players[turn]); logInd++; // turn = Math.Abs(turn - 1); } b.PrintBoard2(f); Console.WriteLine("tie"); return(null); //in case of a game beyond max moves, its a tie. }