Exemple #1
0
        public GoGameState GetGameState(Guid gameId)
        {
            using (var ctx = new GoGEntities())
            {
                var g = ctx.Games.FirstOrDefault(game => game.GameId == gameId);
                if (g == null)
                {
                    return(null);
                }

                var goMoveHistory = new List <GoMoveHistoryItem>();
                foreach (var h in g.Moves.OrderBy(h => h.Sequence))
                {
                    var newHistoryItem = new GoMoveHistoryItem();

                    newHistoryItem.Sequence = h.Sequence;

                    // Translate Move from db.
                    newHistoryItem.Move = new GoMove
                    {
                        Color    = h.IsBlack ? GoColor.Black : GoColor.White,
                        Position = h.Position,
                        MoveType = (MoveType)h.MoveType
                    };

                    // Translate Result from db.
                    newHistoryItem.Result = new GoMoveResult(h.Captured);

                    goMoveHistory.Add(newHistoryItem);
                }

                var p1 = new GoPlayer
                {
                    Level      = g.Player1Level,
                    Name       = g.Player1Name,
                    PlayerType = (PlayerType)g.Player1Type,
                    Score      = g.Player1Score,
                };
                var p2 = new GoPlayer
                {
                    Level      = g.Player2Level,
                    Name       = g.Player2Name,
                    PlayerType = (PlayerType)g.Player2Type,
                    Score      = g.Player2Score
                };
                var rval = new GoGameState(g.Size,
                                           p1, p2,
                                           (GoGameStatus)g.Status,
                                           g.BlacksTurn ? GoColor.Black : GoColor.White,
                                           g.BlackStones, g.WhiteStones,
                                           goMoveHistory,
                                           g.WinMargin);
                return(rval);
            }
        }
Exemple #2
0
        private static void UpdateDbMove(Move move, GoMoveHistoryItem goMoveHistoryItem)
        {
            // We never update moves, we only add and remove them.  So I've
            // commented this code until I see some problem in the future. -- Chris Bordeman

            //move.Captured = goMoveHistoryItem.Result.CapturedStones;
            //move.IsBlack = goMoveHistoryItem.Move.Color == GoColor.Black;
            //move.MoveType = (byte)goMoveHistoryItem.Move.MoveType;
            //if (goMoveHistoryItem.Move.MoveType == MoveType.Normal)
            //    move.Position = goMoveHistoryItem.Move.Position;
        }
Exemple #3
0
        private static Move ConvertToDbMove(GoMoveHistoryItem goMoveHistoryItem, int position, Guid gameId)
        {
            var move = new Move();

            if (goMoveHistoryItem.Move.MoveType == MoveType.Normal)
            {
                move.Position = goMoveHistoryItem.Move.Position;
            }
            move.GameId   = gameId;
            move.Captured = goMoveHistoryItem.Result.CapturedStones;
            move.IsBlack  = goMoveHistoryItem.Move.Color == GoColor.Black;
            move.MoveType = (byte)goMoveHistoryItem.Move.MoveType;
            move.Sequence = position;

            return(move);
        }