public override void ChooseMovesAsPBar(MoveResult moveResult)
        {
            Move move = moveResult.Move;

            LogDebugMessage("*** ANTAGONIST (PBar = {0}) ***", move.pBar);
            LogDebugMessage("Slack: {0}", moveResult.Slack);

            double valueOfMove = ScenarioValueFunctions.ClearRunAtBaseScenarioValueFunction.Evaluate(moveResult.Slack);

            LogDebugMessage("Value of move: {0}", valueOfMove);

            // Defend against an enemy attack on your base:
            for (int tankNumber = 0; tankNumber < Constants.TANKS_PER_PLAYER; tankNumber++)
            {
                LogDebugMessage("Tank number: {0}", tankNumber);
                TankActionRecommendation recommendation = moveResult.GetRecommendedTankActionsByPlayerAndTankNumber(move.pBar, tankNumber);
                if (recommendation.IsAMoveRecommended)
                {
                    TankSituation tankSituation
                        = GameSituation.GetTankSituationByPlayerAndTankNumber(move.pBar, tankNumber);
                    TankAction recommendedTankAction = recommendation.RecommendedTankAction;
                    LogDebugMessage("Recommended tank action: {0}", recommendedTankAction);

                    tankSituation.AdjustTankActionValue(recommendedTankAction, valueOfMove);
                }
                else
                {
                    LogDebugMessage("No moves recommended");
                }
            }
        }
Example #2
0
    private void RpcSetGameSituation(SerializedGameSituation serializedGameSituation)
    {
        if (!isLocalPlayer)
        {
            return;
        }
        GameSituation gameSituation = SerializedGameSituation.Deserealize(serializedGameSituation);

        clientManager.SetGameSituation(gameSituation);

        if (gameSituation.GameStatus == GameStatus.OpponentExits)
        {
            clientManager.Block(true, PlayerColor.White);
            clientManager.Block(true, PlayerColor.Black);
            return;
        }
        if ((playerColor == PlayerColor.White) && (gameSituation.IsWhiteMoving))
        {
            clientManager.Block(false, PlayerColor.White);
        }
        else if ((playerColor == PlayerColor.Black) && (!gameSituation.IsWhiteMoving))
        {
            clientManager.Block(false, PlayerColor.Black);
        }
        else
        {
            clientManager.Block(true, playerColor);
        }
    }
Example #3
0
        public static bool DecisionNeeded(this GameBoard board, GameSituation situation)
        {
            var  legalEndpoints = board.GetLegalEndpoints(situation.BoardLocation, situation.Spin);
            bool win            = legalEndpoints.ResultsInWin();

            return(!win && legalEndpoints.Count() > 1);
        }
Example #4
0
 public void SetGameSituation(GameSituation gameSituation)
 {
     if (gameSituation.GameStatus == GameStatus.OpponentExits)
     {
         if (endGame)
         {
             return;
         }
         endGame = true;
         NotifyOpponentExits();
         return;
     }
     if (gameSituation.GameStatus == GameStatus.Checkmate)
     {
         endGame = true;
         if (gameSituation.IsWhiteMoving)
         {
             NotifyCheckMateWhite();
         }
         else
         {
             NotifyCheckMateBlack();
         }
     }
     board.SetGameSituation(gameSituation);
 }
Example #5
0
    public void InitializeBoard(GameSituation gameSituation)
    {
        if (pieces.Values.Count != 0)
        {
            foreach (GameObject piece in pieces.Values)
            {
                Destroy(piece);
            }
            pieces.Clear();
        }

        for (int i = 0; i < 8; ++i)
        {
            for (int j = 0; j < 8; ++j)
            {
                Cell pieceCell = new Cell(i, j);
                var  piece     = gameSituation.PiecesLocation[i, j];
                if (piece.Item1 == ChessPieceType.None)
                {
                    continue;
                }
                GameObject newPiece = CreatePiece(piece.Item1, piece.Item2, pieceCell);
                pieces.Add(pieceCell, newPiece);
                Piece pieceScript = newPiece.GetComponent <Piece>();
                if (gameSituation.AllowedMoves.ContainsKey(pieceCell))
                {
                    pieceScript.AllowedMoves = gameSituation.AllowedMoves[pieceCell];
                }
                else
                {
                    pieceScript.AllowedMoves = new HashSet <Cell>();
                }
            }
        }
    }
        public override void ChooseMovesAsP(MoveResult moveResult)
        {
            Move move = moveResult.Move;

            LogDebugMessage("*** PROTAGONIST (P = {0}) ***", move.p);
            LogDebugMessage("Slack: {0}", moveResult.Slack);

            double valueOfMove = ScenarioValueFunctions.ClearRunAtBaseScenarioValueFunction.Evaluate(moveResult.Slack);

            LogDebugMessage("Value of move: {0}", valueOfMove);

            // Attack the enemy base:
            LogDebugMessage("Tank number: {0}", move.i);
            TankActionRecommendation recommendation
                = moveResult.GetRecommendedTankActionsByPlayerAndTankNumber(move.p, move.i);

            if (recommendation.IsAMoveRecommended)
            {
                TankSituation tankSituation         = GameSituation.GetTankSituationByPlayerAndTankNumber(move.p, move.i);
                TankAction    recommendedTankAction = recommendation.RecommendedTankAction;
                LogDebugMessage("Recommended tank action: {0}", recommendedTankAction);

                tankSituation.AdjustTankActionValue(recommendedTankAction, valueOfMove);
            }
            else
            {
                LogDebugMessage("No moves recommended");
            }
        }
Example #7
0
    private void Move(PlayerAct playerAct)
    {
        GameSituation gameSituation = chessGame.MakeMove(playerAct.From, playerAct.To);

        whitePlayer.SetGameSituation(gameSituation);
        blackPlayer.SetGameSituation(gameSituation);
    }
Example #8
0
 public void SetGameSituation(GameSituation gameSituation)
 {
     if (((gameSituation.IsWhiteMoving) && (playerColor == PlayerColor.White)) ||
         ((!gameSituation.IsWhiteMoving) && (playerColor == PlayerColor.Black)))
     {
         uciAdapter.SetGameSituation(gameSituation);
     }
 }
Example #9
0
 public int GetMove(GameSituation situation)
 {
     if (!situation.LegalMoves.Contains(situation.BoardLocation + situation.Spin))
     {
         throw new InvalidOperationException();
     }
     return(situation.BoardLocation + situation.Spin);
 }
        private bool TrySetBestMoveSoFar(GameState currGameState, GameSituation gameSituation)
        {
            TankActionSet actionSet
                = gameSituation.GenerateTankActions(YourPlayerIndex, currGameState.Tick);

            Coordinator.SetBestMoveSoFar(actionSet);
            return(true);
        }
Example #11
0
 public void SetGameSituation(GameSituation gameSituation)
 {
     if (state != State.Ready)
     {
         throw new System.Exception("Движок не готов к ходу");
     }
     SendCommand("position fen " + TranslateGameSituationToFen(gameSituation));
     state = State.Run;
     SendCommand("go");
 }
Example #12
0
        public int GetMove(GameSituation situation)
        {
            var bestOption = _paths.FindClosestToEnd(situation.LegalMoves);

            //var bestOptionDistance = _paths[bestOption];
            //var maxOptionDistance = _paths[situation.LegalMoves.Max()];
            //if (bestOptionDistance < maxOptionDistance)
            //    Console.WriteLine($"*** Greedy option not the best for {situation.BoardLocation}-{situation.Spin}");
            return(bestOption);
        }
Example #13
0
        public int GetMove(GameSituation situation)
        {
            var result = _rules.Process(situation.BoardLocation, situation.Spin);

            if (!situation.LegalMoves.Contains(result))
            {
                throw new InvalidOperationException($"Illegal result returned {result}. Legal options: {string.Join(",", situation.LegalMoves)}");
            }
            return(result);
        }
Example #14
0
    public void SetGameSituation(GameSituation gameSituation)
    {
        PlayerColor myColor = gameSituation.IsWhiteMoving ? PlayerColor.White : PlayerColor.Black;

        for (int i = 0; i < 8; ++i)
        {
            for (int j = 0; j < 8; ++j)
            {
                Cell cell  = new Cell(i, j);
                var  piece = gameSituation.PiecesLocation[i, j];
                if (pieces.ContainsKey(cell))
                {
                    GameObject pieceObject       = pieces[cell];
                    Piece      pieceScriptObject = pieceObject.GetComponent <Piece>();
                    if ((pieceScriptObject.PlayerColor == piece.Item2) && (pieceScriptObject.ChessPieceType == piece.Item1))
                    {
                        if (gameSituation.AllowedMoves.ContainsKey(cell))
                        {
                            pieceScriptObject.AllowedMoves = gameSituation.AllowedMoves[cell];
                        }
                        else
                        {
                            pieceScriptObject.AllowedMoves = new HashSet <Cell>();
                        }
                        continue;
                    }
                    else
                    {
                        pieces.Remove(cell);
                        Destroy(pieceObject);
                    }
                }
                if (!pieces.ContainsKey(cell))
                {
                    if (piece.Item1 == ChessPieceType.None)
                    {
                        continue;
                    }
                    GameObject pieceObject       = CreatePiece(piece.Item1, piece.Item2, cell);
                    Piece      pieceScriptObject = pieceObject.GetComponent <Piece>();
                    if (gameSituation.AllowedMoves.ContainsKey(cell))
                    {
                        pieceScriptObject.AllowedMoves = gameSituation.AllowedMoves[cell];
                    }
                    else
                    {
                        pieceScriptObject.AllowedMoves = new HashSet <Cell>();
                    }

                    pieces.Add(cell, pieceObject);
                    continue;
                }
            }
        }
    }
Example #15
0
        /// <summary>
        /// 获得开局时的决策
        /// </summary>
        /// <param name="ThisChessBoard">当前棋盘状态</param>
        /// <returns>下一步决策</returns>
        public QuoridorAction GetFormulaePolicy(ChessBoard ThisChessBoard)
        {
            QuoridorAction NextPolicy = new QuoridorAction(NowAction.Action_Wait, new Point(-1, -1));
            string         CBString   = ChessBoardToString(ThisChessBoard);
            string         LString    = ChessBoardLocationToString(ThisChessBoard, PolicyPlayer);

            if (CBFormulaeList.ContainsKey(CBString))//检测棋盘定式库
            {
                NextPolicy = CBFormulaeList[CBString];
                if (NextPolicy.SkipChessScore == 999)
                {
                    NowGameSituation = GameSituation.PreviousSituation;
                }
            }
            else if (LocationFormulaeList.ContainsKey(LString))//检测位置定式库
            {
                NextPolicy = LocationFormulaeList[LString];
                if (NextPolicy.SkipChessScore == 999)
                {
                    NowGameSituation = GameSituation.PreviousSituation;
                }
            }
            else//直走或者最短路径走
            {
                Point PlayerLocation = ThisChessBoard.Player1Location;
                if (PolicyPlayer == EnumNowPlayer.Player2)
                {
                    PlayerLocation          = ThisChessBoard.Player2Location;
                    NextPolicy.PlayerAction = NowAction.Action_Move_Player2;
                    NextPolicy.ActionPoint  = new Point(PlayerLocation.X - 1, PlayerLocation.Y);
                }
                else
                {
                    NextPolicy.PlayerAction = NowAction.Action_Move_Player1;
                    NextPolicy.ActionPoint  = new Point(PlayerLocation.X + 1, PlayerLocation.Y);
                }
                string ErrorHint = "";
                ErrorHint = NowEvalution.QuoridorRule.CheckMove_NoChange(ThisChessBoard
                                                                         , NextPolicy.ActionPoint.X, NextPolicy.ActionPoint.Y, NextPolicy.PlayerAction);
                if (ErrorHint != "OK")//只能最短路径走
                {
                    List <QuoridorAction> MoveActionList = new List <QuoridorAction>();

                    NowEvalution.AddMoveAction(ref MoveActionList, ThisChessBoard, PolicyPlayer, PlayerLocation);
                    NowEvalution.ActionListEvaluation(ThisChessBoard, ref MoveActionList, PolicyPlayer, 0, 0, -50);
                    NextPolicy = MoveActionList[0];
                }
                if (CheckInitialSituationEnd(ThisChessBoard))
                {
                    NowGameSituation = GameSituation.PreviousSituation;
                }
            }
            FormulaePolicyNum++;
            return(NextPolicy);
        }
        private void EvaluateDodgeBulletScenario(GameState currGameState, GameSituation gameSituation)
        {
            Scenario scenario = new ScenarioToDodgeABullet(currGameState, gameSituation, YourPlayerIndex);

            ScenarioEvaluator.EvaluateScenario(scenario);

            /* NB: There is no need to choose moves as well.
             * This will already be done while evaluating the scenario,
             * since there aren't alternative strategies to choose from,
             * so no MinMax is needed.
             */
        }
Example #17
0
    public ServerManager(IPlayer whitePlayer, IPlayer blackPlayer)
    {
        this.whitePlayer              = whitePlayer;
        this.blackPlayer              = blackPlayer;
        whitePlayer.PlayerActedEvent += SetPlayerAct;
        blackPlayer.PlayerActedEvent += SetPlayerAct;

        chessGame = new ChessGame();
        GameSituation gameSituation = chessGame.InitializeBoard();

        whitePlayer.SetGameSituation(gameSituation);
        blackPlayer.SetGameSituation(gameSituation);
    }
Example #18
0
 private void Awake()
 {
     GamePhase = GameSituation.setPieces;
     numOfDeployedBluePieces = 0;
     unityObjects            = new Dictionary <string, GameObject>();
     GameObject[] objects = GameObject.FindGameObjectsWithTag("unityObjects");
     foreach (GameObject go in objects)
     {
         unityObjects.Add(go.name, go);
         //print("go.name= " + go.name);
     }
     print("Amount of Object is = " + unityObjects.Count);
     InitializeEnemy();
     listener = new Listener();
     rooms    = new List <string>();
 }
Example #19
0
 public void SetGameSituation(GameSituation gameSituation)
 {
     clientManager.SetGameSituation(gameSituation);
     if ((playerColor == PlayerColor.White) && (gameSituation.IsWhiteMoving))
     {
         clientManager.Block(false, PlayerColor.White);
     }
     else if ((playerColor == PlayerColor.Black) && (!gameSituation.IsWhiteMoving))
     {
         clientManager.Block(false, PlayerColor.Black);
     }
     else
     {
         clientManager.Block(true, PlayerColor.White);
         clientManager.Block(true, PlayerColor.Black);
     }
 }
Example #20
0
    private void Exit(PlayerAct playerAct)
    {
        IPlayer player;

        if (playerAct.PlayerColor == PlayerColor.White)
        {
            player = blackPlayer;
        }
        else
        {
            player = whitePlayer;
        }
        GameSituation gameSituation = new GameSituation
        {
            GameStatus = GameStatus.OpponentExits
        };

        player.SetGameSituation(gameSituation);
    }
Example #21
0
        private void Say(GameSituation status)
        {
            switch (status)
            {
            case GameSituation.Idle:
                Console.ForegroundColor = ConsoleColor.White;
                break;

            case GameSituation.ActiveTest:
                Console.ForegroundColor = ConsoleColor.Yellow;
                break;

            case GameSituation.InactiveTest:
                Console.ForegroundColor = ConsoleColor.Blue;
                break;

            case GameSituation.AnswerTest:
                Console.ForegroundColor = ConsoleColor.Green;
                break;

            case GameSituation.ActiveNumeric:
                Console.ForegroundColor = ConsoleColor.Yellow;
                break;

            case GameSituation.InactiveNumeric:
                Console.ForegroundColor = ConsoleColor.Blue;
                break;

            case GameSituation.AnswerNumeric:
                Console.ForegroundColor = ConsoleColor.Green;
                break;
            }
            Console.Write("[Состояние]: ");
            Console.WriteLine(status);
            Console.ResetColor();
        }
Example #22
0
    public void EnterFreeMode() {
        Situation = GameSituation.Free;
		ZonesParentGO.SetActive (false);
        if (currentBuildingPrototype != null)
        {
            Destroy(currentBuildingPrototype.MainTransform.gameObject);
            currentBuildingPrototype = null;
        }
    }
Example #23
0
 public void EnterBuildingMode() {
     UnselectAllUnits();
     Situation = GameSituation.Building;
     var go = (GameObject)Instantiate(Resources.Load("TownHallBuilding"));
     var bm = go.GetComponent<BuildingManager>();
     bm.Data = new BuildingData();
     bm.Data.Size = new Vector2(5, 5);
     bm.Data.State = BuildingState.Prototype;
     currentBuildingPrototype = bm;
 }
Example #24
0
 public ScenarioToDodgeABullet(GameState gameState, GameSituation gameSituation, int yourPlayerIndex)
     : base(gameState, gameSituation)
 {
     YourPlayerIndex = yourPlayerIndex;
 }
Example #25
0
 public GameResult(GameSituation situation, GameModel model)
 {
     Situation = situation;
     Model     = model;
 }
        protected override void ChooseMoves()
        {
            bool moveSet = false;

            try
            {
                // TODO: Clear game state cache data for previous tick to save memory
                GameState     currGameState = Game.Current.CurrentTurn.GameState;
                GameSituation gameSituation = new GameSituation(currGameState);
                gameSituation.UpdateSituation();
                // GameSituationsByTick[currGameState.Tick] = gameSituation;

                try
                {
                    if (SolverState != SolverState.StoppingChoosingMoves)
                    {
                        EvaluateScenarioOfApplyingLockDownActions(currGameState, gameSituation);
                        moveSet = TrySetBestMoveSoFar(currGameState, gameSituation);
                    }
                    if (SolverState != SolverState.StoppingChoosingMoves)
                    {
                        EvaluateDodgeBulletScenario(currGameState, gameSituation);
                        moveSet = TrySetBestMoveSoFar(currGameState, gameSituation);
                    }
                    if (SolverState != SolverState.StoppingChoosingMoves)
                    {
                        EvaluateScenarioOfAttackingEnemyBase(currGameState, gameSituation);
                        moveSet = TrySetBestMoveSoFar(currGameState, gameSituation);
                    }
                    if (SolverState != SolverState.StoppingChoosingMoves)
                    {
                        EvaluateScenarioOfAttackingAnEnemyTank(currGameState, gameSituation);
                        moveSet = TrySetBestMoveSoFar(currGameState, gameSituation);
                    }
                    if (SolverState != SolverState.StoppingChoosingMoves)
                    {
                        EvaluateScenarioToAttackLockedDownEnemyTank(currGameState, gameSituation);
                        moveSet = TrySetBestMoveSoFar(currGameState, gameSituation);
                    }
                    if (SolverState != SolverState.StoppingChoosingMoves)
                    {
                        EvaluateScenarioOfAttackingAnUnarmedTank(currGameState, gameSituation);
                        moveSet = TrySetBestMoveSoFar(currGameState, gameSituation);
                    }

                    // Maxi-min scenarios...

                    if (SolverState != SolverState.StoppingChoosingMoves)
                    {
                        EvaluateRunAtBaseScenario(currGameState, gameSituation);
                        moveSet = TrySetBestMoveSoFar(currGameState, gameSituation);
                    }

                    if (!gameSituation.AreAllTankActionsGenerated(YourPlayerIndex))
                    {
                        EvaluateLockDownScenario(currGameState, gameSituation);
                        moveSet = TrySetBestMoveSoFar(currGameState, gameSituation);
                    }
                }
                finally
                {
                    // Always avoid hug me scenarios:
                    EvaluateScenarioOfFriendlyTanksBlockingEachOther(currGameState, gameSituation);
                    moveSet = TrySetBestMoveSoFar(currGameState, gameSituation);
                }
                moveSet = TrySetBestMoveSoFar(currGameState, gameSituation);
                return;
            }
            catch
            {
                // Shortest Path Bot code:
                if (!moveSet)
                {
                    ChooseShortestPathBotMoves();
                }
            }
        }
        private void EvaluateScenarioToAttackLockedDownEnemyTank(GameState currGameState, GameSituation gameSituation)
        {
            Scenario attackLockedDownEnemyTankScenario = new ScenarioToAttackLockedDownEnemyTank(currGameState, gameSituation, YourPlayerIndex);

            ScenarioEvaluator.EvaluateScenarioAndChooseMoves(attackLockedDownEnemyTankScenario, YourPlayerIndex);
        }
        private void EvaluateLockDownScenario(GameState currGameState, GameSituation gameSituation)
        {
            Scenario lockDownScenario = new LockDownEnemyTankForOtherTankToDestroyScenario(currGameState, gameSituation);

            ScenarioEvaluator.EvaluateScenarioAndChooseMoves(lockDownScenario, YourPlayerIndex);
        }
        private void EvaluateRunAtBaseScenario(GameState currGameState, GameSituation gameSituation)
        {
            Scenario runAtBaseScenario = new ClearRunAtBaseScenario(currGameState, gameSituation);

            ScenarioEvaluator.EvaluateScenarioAndChooseMoves(runAtBaseScenario, YourPlayerIndex);
        }
        private void EvaluateScenarioOfDodgingBullets(GameState currGameState, GameSituation gameSituation)
        {
            Scenario scenario = new ScenarioToDodgeABullet(currGameState, gameSituation, YourPlayerIndex);

            ScenarioEvaluator.EvaluateScenarioAndChooseMoves(scenario, YourPlayerIndex);
        }
Example #31
0
 public RockPaperScissorsLizardSpock(string you, string opponent, GameSituation situation)
     : base(you, opponent, situation)
 {
 }
        private void EvaluateScenarioOfApplyingLockDownActions(GameState currGameState, GameSituation gameSituation)
        {
            Scenario scenario = new ScenarioToApplyLockDownActions(currGameState, gameSituation);

            ScenarioEvaluator.EvaluateScenario(scenario);

            /* NB: There is no need to choose moves as well.
             * This will already be done while evaluating the scenario,
             * since there aren't alternative strategies to choose from,
             * so no MinMax is needed.
             */
        }
Example #33
0
 public ConnectFour(string you, string opponent, GameSituation situation)
     : base(you, opponent, situation)
 {
 }
Example #34
0
	public void EnterZoneMode() {
		UnselectAllUnits ();
		ZonesParentGO.SetActive (true);
		Situation = GameSituation.Zone;
	}
        private void EvaluateScenarioOfAttackingAnEnemyTank(GameState currGameState, GameSituation gameSituation)
        {
            Scenario scenario = new ScenarioOfAttackingAnEnemyTank(currGameState, gameSituation, YourPlayerIndex);

            ScenarioEvaluator.EvaluateScenario(scenario);
        }
Example #36
0
 public BaseGame(string you, string opponent, GameSituation situation)
 {
     You = you;
     Opponent = opponent;
     Situation = situation;
 }