예제 #1
0
        // used by both human/ai players to occupy tile, add PlayerMove,
        // increment counters, check win/tie state, change player turn
        void PlayPiece(Tile tile)
        {
            tile.EnableAndSetTilePiece(CurrentTurn);
            ui.SetLastMoveMarker(tile);

            // Move data struct for state change management
            var move = new PlayerMove {
                player     = CurrentTurn,
                moveTile   = tile,
                turnNumber = currentTurnNum,
            };

            playerMoves.Push(move);

            // increment played pieces and turn number
            gridBoard.playedPiecesCount++;
            currentTurnNum++;

            // checks for wins/tie; return if win/tie detected
            var score = Evaluation.StaticEvaluation(GridBoard.Board, tile);

            Debug.Log(string.Format("{0}: [{1}, {2}]; {3}", CurrentTurn.playerName, tile.x, tile.y, score));
            if (CheckResult(score))
            {
                return;
            }

            gomoku.AddAdjacentTiles(GridBoard.Board, tile, gomoku.adjTiles);

            // Go to next player's turn
            CurrentTurn = CurrentTurn == Black ? White : Black;

            UpdateGameStatus();
            CheckIfComputerTurn();
        }
예제 #2
0
        public int MinimaxAB(List <Tile> adj, Tile move, Player player, int depth, int alpha, int beta)
        {
            evalCount++;
            int score = Evaluation.StaticEvaluation(GridBoard.Board, move); // check for wins

            if (Math.Abs(score) >= 100000 ||
                depth >= Game.Instance.maxComputeDepth ||
                stopwatch.ElapsedMilliseconds > Game.Instance.timeoutMs)
            {
                return(score);
            }
            // if(adj.Count > maxEvalAdj)
            //     maxEvalAdj = adj.Count;

            if (player == Game.Black) // maximize
            // maxCount++;
            {
                int max = int.MinValue;

                for (int i = 0; i < adj.Count; ++i)
                {
                    if (adj[i].occupied)
                    {
                        continue;
                    }

                    adj[i].player = player;
                    max           = Math.Max(max, MinimaxAB(adj, adj[i], player.opp, depth + 1, alpha, beta));

                    adj[i].player = null;

                    alpha = Math.Max(alpha, max);
                    if (alpha >= beta)
                    {
                        // alphaBreak++;
                        break;
                    }
                }
                return(max);
            }
            else // minimize
                 // minCount++;
            {
                int min = int.MaxValue;

                for (int i = 0; i < adj.Count; ++i)
                {
                    if (adj[i].occupied)
                    {
                        continue;
                    }

                    adj[i].player = player;
                    min           = Math.Min(min, MinimaxAB(adj, adj[i], player.opp, depth + 1, alpha, beta));

                    adj[i].player = null;

                    beta = Math.Min(beta, min);
                    if (beta <= alpha)
                    {
                        // betaBreak++;
                        break;
                    }
                }
                return(min);
            }
        }