Exemple #1
0
 protected float GetScore(Board board, IGameAgent gameAgent, float alpha = float.MinValue, float beta = float.MaxValue, int depth = int.MaxValue)
 {
     Game.State gameState = game.GetState(board, gameAgent);
     if (gameState != Game.State.playing || depth == 0)
     {
         return(game.GetScore(board, gameAgent, gameState));
     }
     else
     {
         float           score         = float.MinValue;
         List <Position> possibleMoves = game.GetPossibleMoves(board, gameAgent);
         for (int i = 0; i < possibleMoves.Count; ++i)
         {
             Board newBoard = new Board(board, gameAgent, possibleMoves[i]);
             if (i == 0)
             {
                 score = -GetScore(newBoard, gameAgent.opponent, -beta, -alpha, depth - 1);
             }
             else
             {
                 score = -GetScore(newBoard, gameAgent.opponent, -alpha - 1, -alpha, depth - 1);
             }
             if (alpha < score && score < beta)
             {
                 score = -GetScore(newBoard, gameAgent.opponent, -beta, -score, depth - 1);
             }
             alpha = Mathf.Max(alpha, score);
             if (beta <= alpha)
             {
                 break;
             }
         }
         return(alpha);
     }
 }
Exemple #2
0
 public Message CreateJoinedMessage(Guid gameId, string joinedPlayerName, Game.State gameState)
 {
     return(CreateMessage(gameId, null, "joined", new
     {
         joinedPlayerName,
         gameState = gameState.ToString()
     }));
 }
Exemple #3
0
    // Start is called before the first frame update
    void Start()
    {
        castingArrowSpriteRenderer         = this.gameObject.AddComponent <SpriteRenderer>();
        castingArrowSpriteRenderer.sprite  = castingArrow;
        castingArrowSpriteRenderer.enabled = false;

        gameState = MainSceneController.GetInstance().GetState();
    }
Exemple #4
0
 private void OnInitializeEnter(Game.State state)
 {
     if (!state.Equals(Game.State.InitGame))
     {
         return;
     }
     Initialize();
 }
Exemple #5
0
        void OnInitialize(Game.State state)
        {
            if (state != Game.State.InitGame)
            {
                return;
            }

            Initialize();
        }
    void Update()
    {
        clearTime += Time.deltaTime;

        // Allow some time for encounter trigger to clear
        if (clearTime > 2.5f)
        {
            clearTime = 0;
            gameState = MainSceneController.GetInstance().GetState();
        }
    }
Exemple #7
0
 private void NextTrun()
 {
     if (turn == Game.State.X)
     {
         turn = Game.State.O;
     }
     else
     {
         turn = Game.State.X;
     }
 }
Exemple #8
0
        private void OnGameStateChanged(Game.State state)
        {
            switch (state)
            {
            case Game.State.InGame:
                _overlay.FadeOut();
                break;

            case Game.State.GameOver:
                _menu.Show();
                break;
            }
        }
Exemple #9
0
    // Update is called once per frame
    void Update()
    {
        clearTime += Time.deltaTime;

        // Check game state
        if (clearTime > 1 && MainSceneController.GetInstance() != null)
        {
            clearTime = 0;
            gameState = MainSceneController.GetInstance().GetState();
        }

        // Check if primary mouse button is down
        if (Input.GetMouseButton(1) && gameState == Game.State.CATCHING)
        {
            castingArrowSpriteRenderer.enabled = true;

            // Clear old bait instances
            if (baitInstance != null)
            {
                DestroyImmediate(baitInstance);
                baitInstance = null;
            }

            // Update casting arrow position
            castingArrowSpriteRenderer.transform.position = player.position;
            transform.position = new Vector3(transform.position.x, transform.position.y, 0.5f);

            // Calculate world point
            Vector3 worldPoint = Input.mousePosition;
            worldPoint.Set(worldPoint.x, worldPoint.y, 2);
            worldPoint = Camera.main.ScreenToWorldPoint(worldPoint);
            Vector2 worldPoint2d = new Vector2(worldPoint.x, worldPoint.y);

            // Point casting arrow to calculated position
            Vector3    vectorToTarget = new Vector3(worldPoint2d.x, worldPoint2d.y) - new Vector3(player.position.x, player.position.y);
            float      angle          = (Mathf.Atan2(vectorToTarget.y, vectorToTarget.x) * Mathf.Rad2Deg) + 90;
            Quaternion q = Quaternion.AngleAxis(angle, Vector3.forward);
            transform.rotation = q;
        }
        else
        {
            castingArrowSpriteRenderer.enabled = false;
        }

        // Check if primary mouse button has been clicked and then released
        if (Input.GetMouseButtonUp(1) && gameState == Game.State.CATCHING)
        {
            released = true;
        }
    }
Exemple #10
0
        public void Draw(SpriteBatch spriteBatch, Game.State currentState)
        {
            foreach (var word in _words)
            {
                word.Draw(spriteBatch);
            }

            if (currentState == Game.State.Playing)
            {
                foreach (var constellation in _constellations)
                {
                    constellation?.Draw(spriteBatch);
                }
            }
        }
    public override float GetReward(Game.State gameState, Board board, IGameAgent gameAgent)
    {
        switch (gameState)
        {
        case Game.State.win:
            return(+(1 - (board.moveIndex - 4) / 5f));

        case Game.State.draw:
            return(0.1f);

        case Game.State.loss:
            return(-(1 - (board.moveIndex - 4) / 5f));

        default:
            return(0);
        }
    }
Exemple #12
0
 protected float GetScore(Board board, IGameAgent gameAgent, int depth = int.MaxValue)
 {
     Game.State gameState = game.GetState(board, gameAgent);
     if (gameState != Game.State.playing || depth == 0)
     {
         return(game.GetScore(board, gameAgent, gameState));
     }
     else
     {
         float           score         = float.MinValue;
         List <Position> possibleMoves = game.GetPossibleMoves(board, gameAgent);
         for (int i = 0; i < possibleMoves.Count; ++i)
         {
             score = Mathf.Max(score, -GetScore(new Board(board, gameAgent, possibleMoves[i]), gameAgent.opponent, depth - 1));
         }
         return(score);
     }
 }
Exemple #13
0
        public Game.State Move(int?gameId, int position)
        {
            var game = _db.Games.Get(gameId);

            if (game.Turns.Any())
            {
                FillField(game);
            }

            if (!gameLogic.UserMove(position))
            {
                return(Game.State.NotFinish);
            }

            var turn = new Turn(true, position);

            game.Turns.Add(turn);

            Game.State check = gameLogic.CheckGameState();

            if (check != Game.State.NotFinish)
            {
                game.Result = check;
                _db.Games.Update(game);
                _db.SaveDb();
                return(check);
            }

            turn = new Turn(false, gameLogic.BotMove());
            game.Turns.Add(turn);

            check = gameLogic.CheckGameState();
            if (check != Game.State.NotFinish)
            {
                game.Result = check;
                _db.Games.Update(game);
                _db.SaveDb();
                return(check);
            }
            _db.Games.Update(game);
            _db.SaveDb();
            return(Game.State.NotFinish);
        }
Exemple #14
0
 protected float GetScore(Board board, IGameAgent gameAgent, float alpha = float.MinValue, float beta = float.MaxValue, int depth = int.MaxValue)
 {
     Game.State gameState = game.GetState(board, gameAgent);
     if (gameState != Game.State.playing || depth == 0)
     {
         return(game.GetScore(board, gameAgent, gameState));
     }
     else
     {
         float           score         = float.MinValue;
         List <Position> possibleMoves = game.GetPossibleMoves(board, gameAgent);
         //--- Killer heuristic ---
         for (int i = 0; i < possibleMoves.Count; ++i)
         {
             if (killers.Contains(possibleMoves[i]))
             {
                 Position move = possibleMoves[i];
                 possibleMoves.RemoveAt(i);
                 possibleMoves.Insert(0, move);
             }
         }
         //-------------------------
         for (int i = 0; i < possibleMoves.Count; ++i)
         {
             score = Mathf.Max(score, -GetScore(new Board(board, gameAgent, possibleMoves[i]), gameAgent.opponent, -beta, -alpha, depth - 1));
             beta  = Mathf.Max(score, beta);
             if (beta <= alpha)
             {
                 //--- Killer heuristic ---
                 killers.Enqueue(possibleMoves[i]);
                 if (2 < killers.Count)
                 {
                     killers.Dequeue();
                 }
                 //-------------------------
                 break;
             }
         }
         return(score);
     }
 }
Exemple #15
0
        private void ProcessGameState(Game.State state)
        {
            switch (state)
            {
            case Game.State.StartNewGame:
                //numericUpDown1.Value = _game.ElementsCount;
                break;

            case Game.State.PlayerMoved:
                break;

            case Game.State.WaitingMove:
                break;

            case Game.State.PlayerWon:
                MessageBox.Show($@"Ура! Вы угадали число!{Environment.NewLine}Количество ходов: {_game.Moves.Count}", @"Победа!");
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(state), state, @"Unknown game state!");
            }
        }
Exemple #16
0
    void controlState()
    {
        if (isBlockingState(state))
        {
          state = game.Advance();
        }

        while (true)
        {
          if (isBlockingState(state))
          {
        if (state == Game.State.NeedNumber)
        {
          handleNeedNumber();
        }
        else if (state == Game.State.NeedContinueRound)
        {
          handleNeedContinueRound();
        }
        else if (state == Game.State.NeedName)
        {
          handleNeedName();
        }
        else if (state == Game.State.HaveRoundEnd)
        {
          handleHaveRoundEnd();
        }
        return;
          }
          else
          {
        if (state == Game.State.HaveHighScore)
        {
          setHighscoreLabel();
        }
        else if (state == Game.State.HaveThatNumber)
        {
          if (isAnimating)
          {
            isAnimating = false;
          }
          else
          {
            isAnimating = true;

            StartCoroutine(playThatNumberSelectionAnimation());

            return;
          }
        }

        state = game.Advance();
          }
        }
    }
 public NotStartedGame()
 {
     _state = new Game.State(Game.GameState.NotStarted, "creator", Common.Move.Rock);
 }