}//end of Max method private int Min(int max) { int returnValue = int.MaxValue; if(turnTimer.Elapsed.TotalMilliseconds >= maxTurnTime) { timeExpired = true; return returnValue; } currentDepth++; Game.PLAYERS human = Delinquent.GetGame().GetHumanPlayer(); List<Move> moves = Delinquent.GetGame().MoveGenerator(Delinquent.GetGame().GetHumanPlayer()); if(human == Game.PLAYERS.P1) { if(moves.Count == 0 || Delinquent.GetGame().PeekRemoval().GetPiece() == Game.PIECES.P1_KING) { returnValue = 999999999; } } else { if(moves.Count == 0 || Delinquent.GetGame().PeekRemoval().GetPiece() == Game.PIECES.P2_KING) { returnValue = 999999999; } } if(returnValue != 999999999) { if(currentDepth == maxDepth) { returnValue = Eval(moves, false); } else { foreach(Move move in moves) { if(timeExpired) { break; } Delinquent.GetGame().TryMove(move); int moveScore = Max(returnValue); if(moveScore < returnValue) { returnValue = moveScore; } Delinquent.GetGame().UndoMove(move); if(returnValue < max) { break; } } } } currentDepth--; return returnValue; }//end of Min method
}//end of GetSetupInput method public int[] GetUserMove() { int[] move; bool validMoveReceived = false; do { Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine("Enter a move: "); string moveString = Console.ReadLine(); move = map_move_string(moveString); // Console.WriteLine($"Move=[{move[0]}],[{move[1]}],[{move[2]}],[{move[3]}]"); Game.PLAYERS human = Delinquent.GetGame().GetHumanPlayer(); // Console.WriteLine($"Human={human}"); validMoveReceived = Delinquent.GetGame().IsMoveLegal(move, human); if(!validMoveReceived) { Console.WriteLine("Entered move not legal. Please try again."); } } while(!validMoveReceived); return move; }//end of GetUserMove method
}//end of Min method private int Eval(List<Move> moves, bool forComputer) { int returnValue = 0; bool useTrans = false; long transKey = Delinquent.GetGame().GetCurrentHash(); if(transTable.ContainsKey(transKey)) { Transposition trans = transTable[transKey]; if(trans.Ply() <= currentDepth) { returnValue = trans.Score(); useTrans = true; } } if(!useTrans) { Game.PLAYERS human = Delinquent.GetGame().GetHumanPlayer(); Game.PLAYERS computer = Delinquent.GetGame().GetComputerPlayer(); List<Move> computerMoves; List<Move> humanMoves; if(forComputer) { computerMoves = moves; humanMoves = Delinquent.GetGame().MoveGenerator(human); } else { humanMoves = moves; computerMoves = Delinquent.GetGame().MoveGenerator(computer); } //piece value + board advance + mobility + piece threat if(human == Game.PLAYERS.P1) { int p1Score = EvalP1Score(humanMoves); int p2Score = EvalP2Score(computerMoves); returnValue = p2Score - p1Score; } else { int p1Score = EvalP1Score(computerMoves); int p2Score = EvalP2Score(humanMoves); returnValue = p1Score - p2Score; } transTable[transKey] = new Transposition(currentDepth, returnValue); } return returnValue; }//end of Eval method