Beispiel #1
0
        /// <summary>
        /// A player (Human/Computer) made a move.
        /// </summary>
        /// <param name="message"></param>
        private void OnMoveMade(MoveMade message)
        {
            this.board.Set(message.Row, message.Column, message.Player.Symbol);

            IList <Tuple <int, int> > winnigLineCoords = null;
            var status = GameStatus.Continue;

            if (this.gameWon)
            {
                status = (this.player.Color == PlayerColor.Black) ?
                         GameStatus.BlackWon : GameStatus.WhiteWon;

                winnigLineCoords = GetWinningLine(message.Row, message.Column);
            }

            if (this.totalLines <= 0)
            {
                // no more possible moves
                status = GameStatus.Draw;
            }

            // update the current player only if the game can continue
            if (status == GameStatus.Continue)
            {
                this.player = this.OpponentPlayer(message.Player);
            }

            //
            this.gameServer.Tell(
                new MoveResponse()
            {
                Guid              = this.guid,
                Player            = message.Player,
                NextPlayer        = this.player,
                Row               = message.Row,
                Column            = message.Column,
                MoveStatus        = MoveStatus.Accepted,
                GameStatus        = status,
                WinningLine       = this.winningLine,
                WinningLineCoords = winnigLineCoords
            });

            //
            if (status != GameStatus.Continue)
            {
                // the game is over
                return;
            }

            // let the computer play its own turn
            if (this.player.IsComputer())
            {
                this.Think();
            }
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="message"></param>
        private void HandleMoveMade(MoveMade message)
        {
            this.log.Debug("MoveMade - game={0}, player={1}, row={2}, column={3}",
                           message.Guid, message.Player, message.Row, message.Column);

            GameContext actors;

            this.games.TryGetValue(message.Guid, out actors);
            if (actors != null)
            {
                actors.GameActorRef.Tell(message, Sender);
            }
        }