/// <summary> /// Make move from console /// </summary> /// <returns></returns> public Tuple <int, int> MakeMove() { List <Tuple <int, int> > availablePoints = gameProcessor.GetAvailablePoints(); string move; Tuple <int, int> moveCoords = new Tuple <int, int>(-1, -1); //read from console white input isn`t correct do { move = Console.ReadLine(); move = move.Trim().ToLower(); if (!IsCorrectMove(move)) { //if this is word "pass" - make move pass if (move == "pass") { gameProcessor.PassWithoutMassage(); break; } continue; } //make correct and available move moveCoords = ConsoleInput.ConvertToIntCoords(move); if (availablePoints.Contains(moveCoords)) { gameProcessor.MakeMove(moveCoords); break; } }while (true); return(moveCoords); }
private int Min(int depth, int alpha, int beta) { int bestScore = int.MaxValue; var availableMoves = gameProcessor.GetAvailablePoints(); //pass if there is no available moves if (availableMoves.Count == 0) { List <List <Point> > pointsBeforeMove = CloneGameState(gameProcessor.GetPoints()); gameProcessor.PassWithoutMassage(); int score = MiniMax(depth - 1, alpha, beta, false); bestScore = GetMin(score, bestScore); gameProcessor.UndoMove(pointsBeforeMove); } else { //go deeper in tree for every posible move foreach (var move in availableMoves) { List <List <Point> > pointsBeforeMove = CloneGameState(gameProcessor.GetPoints()); gameProcessor.MakeMove(move); int score = MiniMax(depth - 1, beta, alpha, false); bestScore = GetMin(score, bestScore); beta = GetMin(beta, bestScore); gameProcessor.UndoMove(pointsBeforeMove); //alpha-beta puning if (beta <= alpha) { break; } } } return(bestScore); }