예제 #1
0
        float Estimate(GameState state, Logger.GameMove move)
        {
            int    fieldLevel         = -1;
            string fieldLevelPosition = "";
            float  m = state.table[move.NextFigurePosition].FieldLevel;
            float  l = 0;

            if (state.table[move.NewLevelBuildPosition].FieldLevel < 4)
            {
                l = (state.table[move.NewLevelBuildPosition].FieldLevel + 1) * (state.Distance(state.notOnTurn, move.NewLevelBuildPosition) - state.Distance(state.onTurn, move.NewLevelBuildPosition));
            }
            else
            {
                if (state.Distance(state.notOnTurn, move.NewLevelBuildPosition, out fieldLevel, out fieldLevelPosition) == 1)
                {
                    l = (state.table[move.NewLevelBuildPosition].FieldLevel + 1) * (fieldLevel - state.table[move.NextFigurePosition].FieldLevel);
                }
            }
            state.Distance(state.onTurn, move.NewLevelBuildPosition, out fieldLevel, out fieldLevelPosition);
            float qme = fieldLevel * state.Distance(state.notOnTurn, fieldLevelPosition);

            state.Distance(state.notOnTurn, move.NewLevelBuildPosition, out fieldLevel, out fieldLevelPosition);
            float qop = fieldLevel * state.Distance(state.onTurn, fieldLevelPosition);

            float q = qme - qop;
            float f = m + l + q;

            return(f);
        }
예제 #2
0
 public void UndoMove(Logger.GameMove move)
 {
     table[move.PreviousFigurePosition].PlayerFigure = table[move.NextFigurePosition].PlayerFigure;
     table[move.NextFigurePosition].PlayerFigure     = 0;
     table[move.NewLevelBuildPosition].FieldLevel--;
     ChangeTurns();
 }
예제 #3
0
        float Estimate(GameState state, Logger.GameMove move)
        {
            float m = state.table[move.NextFigurePosition].FieldLevel;
            float l = state.table[move.NewLevelBuildPosition].FieldLevel + 1;
            float myDistance = 0, opponentDistance = 0;

            myDistance       = state.Distance(state.onTurn, move.NewLevelBuildPosition);
            opponentDistance = state.Distance(state.notOnTurn, move.NewLevelBuildPosition);
            l = l * (myDistance - opponentDistance);
            float f = m + l;

            return(f);
        }
예제 #4
0
        public List <Logger.GameMove> GetPossibleBuilds(Logger.GameMove gameMove)
        {
            List <Logger.GameMove> possibleBuilds = new List <Logger.GameMove>();

            string[] neighbours = GameState.neighbours[gameMove.NextFigurePosition];
            for (int i = 0; i < neighbours.Length; i++)
            {
                if ((table[neighbours[i]].PlayerFigure == 0 || neighbours[i] == gameMove.PreviousFigurePosition) && table[neighbours[i]].FieldLevel < 4)
                {
                    Logger.GameMove gameMoveWithBuild = new Logger.GameMove(gameMove);
                    gameMoveWithBuild.NewLevelBuildPosition = neighbours[i];
                    possibleBuilds.Add(gameMove);
                }
            }
            return(possibleBuilds);
        }
예제 #5
0
        public List <Logger.GameMove> GetPossibleMoves(string currentPosition)
        {
            List <Logger.GameMove> possibleMoves = new List <Logger.GameMove>();

            string[] neighbours = GameState.neighbours[currentPosition];
            for (int i = 0; i < neighbours.Length; i++)
            {
                if (table[neighbours[i]].PlayerFigure == 0 && table[neighbours[i]].FieldLevel - 1 <= table[currentPosition].FieldLevel)
                {
                    Logger.GameMove gameMove = new Logger.GameMove();
                    gameMove.PreviousFigurePosition = currentPosition;
                    gameMove.NextFigurePosition     = neighbours[i];
                    possibleMoves.Add(gameMove);
                }
            }
            return(possibleMoves);
        }
예제 #6
0
        public void CalculateMove()
        {
            PlayerFigure randomFigure;

            do
            {
                randomFigure = gameController.FetchMyFigure(this, rnd.Next(2)).GetComponent <PlayerFigure>();
            }while (!randomFigure.enabled);

            var possibleMoves = gameController.gameState.GetPossibleMoves(randomFigure.position);

            var possibleBuilds = gameController.gameState.GetPossibleBuilds(possibleMoves);

            int random = rnd.Next(possibleBuilds.Count);

            nextGameMove = possibleBuilds[random];
        }
예제 #7
0
        public Logger.GameMove Minimax(GameState currentState, bool maximizingPlayer, out float?est, int maxLevel = 3, int current = 0)
        {
            Logger.GameMove bestMove = null;
            if (current < maxLevel - 1)
            {
                float?currentEst = null;
                if (maximizingPlayer)
                {
                    currentEst = float.NegativeInfinity;
                }
                else if (!maximizingPlayer)
                {
                    currentEst = float.PositiveInfinity;
                }
                foreach (var move in currentState.GetPossibleGameMoves())
                {
                    currentState.MakeMove(move);

                    float?retEst = null;
                    Minimax(currentState, !maximizingPlayer, out retEst, maxLevel, current + 1);

                    if (current == 0)
                    {
                        gameController.UI.AddPossibleMove(move, retEst ?? 0f);
                    }

                    currentState.UndoMove(move);
                    if (maximizingPlayer && retEst > currentEst)
                    {
                        currentEst = retEst;
                        bestMove   = move;
                    }
                    else if (!maximizingPlayer && retEst < currentEst)
                    {
                        currentEst = retEst;
                        bestMove   = move;
                    }
                }
                est = currentEst;
                return(bestMove);
            }
            else
            {
                float?currentEst = null;
                if (maximizingPlayer)
                {
                    currentEst = float.NegativeInfinity;
                }
                else if (!maximizingPlayer)
                {
                    currentEst = float.PositiveInfinity;
                }
                foreach (var move in currentState.GetPossibleGameMoves())
                {
                    var retEst = Estimate(currentState, move);
                    if (maximizingPlayer && retEst > currentEst)
                    {
                        currentEst = retEst;
                        bestMove   = move;
                    }
                    else if (!maximizingPlayer && retEst < currentEst)
                    {
                        currentEst = retEst;
                        bestMove   = move;
                    }
                }
                est = currentEst;
                return(bestMove);
            }
        }
예제 #8
0
        public void CalculateMove()
        {
            float?bestMoveValue = 0;

            nextGameMove = Minimax(gameController.gameState, true, out bestMoveValue, depth);
        }
예제 #9
0
 public void AddPossibleMove(Logger.GameMove move, float retValue)
 {
     possibleMovesList.Add(new KeyValuePair <Logger.GameMove, float>(move, retValue));
 }
예제 #10
0
        public void CalculateMove()
        {
            float?bestMoveValue = 0;

            nextGameMove = AlphaBeta(gameController.gameState, true, out bestMoveValue, float.NegativeInfinity, float.PositiveInfinity, depth);
        }