示例#1
0
        public decimal AverageScoreGame(Library.Game game)
        {
            List <UserGame> gameScores = _db.UserGame.Where(g => g.GameId == game.GameId).ToList();
            List <int>      gameInts   = new List <int>();

            foreach (var item in gameScores)
            {
                if (item.Score != null && item.Score != 0)
                {
                    // had to explicitly cast from int? to int to avoid compile error
                    var score = (int)item.Score;
                    gameInts.Add(score);
                }
            }

            var scores = gameInts.ToArray();

            int sum = 0;

            foreach (var item in scores)
            {
                sum += item;
            }
            try
            {
                return((decimal)sum / (decimal)scores.Length);
            }
            catch (DivideByZeroException)
            {
                return(0);
            }
        }
示例#2
0
        public void Beehive_should_remain_static()
        {
            //arrange
            //......
            //..XX..
            //.X..X.
            //..XX..
            //......
            var input = new List <Library.Cell> {
                new Library.Cell(3, 2),
                new Library.Cell(4, 2),
                new Library.Cell(2, 3),
                new Library.Cell(5, 3),
                new Library.Cell(3, 4),
                new Library.Cell(4, 4)
            };

            var game = new Library.Game(6, 5, 1, input); //initialize game with 6x5 board, 1 generation, and given input

            //act
            game.Start();

            //assert
            //......
            //..XX..
            //.X..X.
            //..XX..
            //......
            Assert.True(game.Cell(3, 2).Alive, "This cell should still be alive");
            Assert.True(game.Cell(4, 2).Alive, "This cell should still be alive");
            Assert.True(game.Cell(2, 3).Alive, "This cell should still be alive");
            Assert.True(game.Cell(5, 3).Alive, "This cell should still be alive");
            Assert.True(game.Cell(3, 4).Alive, "This cell should still be alive");
            Assert.True(game.Cell(4, 4).Alive, "This cell should still be alive");
        }
示例#3
0
        public void Blinker_should_oscillate_over_two_periods()
        {
            //arrange
            var input = new List <Library.Cell> {
                new Library.Cell(2, 3),
                new Library.Cell(3, 3),
                new Library.Cell(4, 3)
            };

            var game = new Library.Game(5, 5, 1, input); //initialize game with 5x5 board, 1 generation, and given input

            //act
            game.Start();

            //assert
            Assert.True(game.Cell(3, 2).Alive, "This cell should have come alive");
            Assert.False(game.Cell(2, 3).Alive, "This cell should be dead");
            Assert.True(game.Cell(3, 3).Alive, "This cell should still be alive");
            Assert.False(game.Cell(4, 3).Alive, "This cell should have died");
            Assert.True(game.Cell(3, 4).Alive, "This cell should have come alive");

            //arrange for 2 generations
            game = new Library.Game(5, 5, 2, input); //initialize game with 5x5 board, 2 generations, and given input

            //act
            game.Start();

            //assert
            Assert.False(game.Cell(3, 2).Alive, "This cell should have died");
            Assert.True(game.Cell(2, 3).Alive, "This cell should be alive again");
            Assert.True(game.Cell(3, 3).Alive, "This cell should still be alive");
            Assert.True(game.Cell(4, 3).Alive, "This cell should be alive again");
            Assert.False(game.Cell(3, 4).Alive, "This cell should have died");
        }
示例#4
0
        public Library.Game GetGame(int id)
        {
            Game game = _db.Game.Where(g => g.GameId == id).FirstOrDefault();

            Library.Game gameLib = Mapper.Map(game);
            gameLib.Tags = GetGameTags(game.GameId);
            return(gameLib);
        }
示例#5
0
        // mapping library class to DB entity
        public static DataAccess.Game Map(Library.Game game) => new DataAccess.Game
        {
            GameId      = game.GameId,
            Name        = game.Name,
            Price       = game.Price,
            Description = game.Description,
            DeveloperId = game.DeveloperId,
            Image       = game.Image,
            Trailer     = game.Trailer,

            GameTag = MapTagstoGTs(game.Tags, game.GameId),
        };
        public void Initialize_Sets_Cells_as_product_of_rows_and_columns()
        {
            //arrange
            var columns     = 10;
            var rows        = 5;
            var generations = 150;

            //act
            var game = new Library.Game(columns, rows, generations);

            //assert
            Assert.Equal(50, game.Cells.Count);
        }
        public void Initialize_Sets_NrOfGenerations()
        {
            //arrange
            var columns     = 10;
            var rows        = 5;
            var generations = 150;

            //act
            var game = new Library.Game(columns, rows, generations);

            //assert
            Assert.Equal(generations, game.Generations);
        }
        public void Initialize_Sets_BoardSize()
        {
            //arrange
            var columns = 10;
            var rows    = 5;

            //act
            var game = new Library.Game(columns, rows);

            //assert
            Assert.Equal(columns, game.Columns);
            Assert.Equal(rows, game.Rows);
        }
        public void Initialize_Sets_random_live_cells()
        {
            //arrange
            var columns     = 10;
            var rows        = 5;
            var generations = 150;

            //act
            var game = new Library.Game(columns, rows, generations);

            //assert
            Assert.NotEmpty(game.LiveCells);
        }
示例#10
0
 public bool CreateGame(string gameName, double startingMoney, double bigBlind)
 {
     if (!Games.ContainsKey(gameName))
     {
         var game = new Library.Game(gameName, startingMoney, bigBlind);
         Games[gameName] = game;
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#11
0
        // Bizarre double mapping to combat the fact that the framework is unable to recognize that
        // two identical Library.Game intances are the same. It is, however, able to do so with DB entites
        public ICollection <Library.Game> FilterGames(params ICollection <Library.Game>[] gamesToFilter)
        {
            var priceGames  = gamesToFilter[0].ToList();
            var ratingGames = gamesToFilter[1].ToList();
            var devGames    = gamesToFilter[2].ToList();
            var tagGames    = gamesToFilter[3].ToList();

            int[] gameIdsPrice = new int[priceGames.Count];
            for (int i = 0; i < gameIdsPrice.Length; i++)
            {
                Library.Game gamei  = priceGames[i];
                int          gameId = gamei.GameId;
                gameIdsPrice[i] = gameId;
            }

            int[] gameIdsRating = new int[ratingGames.Count];
            for (int i = 0; i < gameIdsRating.Length; i++)
            {
                Library.Game gamei  = ratingGames[i];
                int          gameId = gamei.GameId;
                gameIdsRating[i] = gameId;
            }

            int[] gameIdsDev = new int[devGames.Count];
            for (int i = 0; i < gameIdsDev.Length; i++)
            {
                Library.Game gamei  = devGames[i];
                int          gameId = gamei.GameId;
                gameIdsDev[i] = gameId;
            }

            int[] gameIdsTag = new int[tagGames.Count];
            for (int i = 0; i < gameIdsTag.Length; i++)
            {
                Library.Game gamei  = tagGames[i];
                int          gameId = gamei.GameId;
                gameIdsTag[i] = gameId;
            }

            List <int>  gameIds = gameIdsPrice.Intersect(gameIdsRating.Intersect(gameIdsDev.Intersect(gameIdsTag))).ToList();
            List <Game> games   = new List <Game>();

            foreach (int number in gameIds)
            {
                Game gameToAdd = _db.Game.Where(g => g.GameId == number).FirstOrDefault();
                games.Add(gameToAdd);
            }
            return(Mapper.Map(games).ToList());
        }
示例#12
0
        public void Toad_should_oscillate_over_two_periods()
        {
            //arrange
            var input = new List <Library.Cell> {
                new Library.Cell(3, 3),
                new Library.Cell(4, 3),
                new Library.Cell(5, 3),
                new Library.Cell(2, 4),
                new Library.Cell(3, 4),
                new Library.Cell(4, 4)
            };

            var game = new Library.Game(6, 6, 1, input); //initialize game with 6x6 board, 1 generation, and given input

            //act
            game.Start();

            //assert that it has oscillated
            Assert.True(game.Cell(4, 2).Alive, "This cell should have come alive");
            Assert.True(game.Cell(2, 3).Alive, "This cell should have come alive");
            Assert.False(game.Cell(3, 3).Alive, "This cell should have died");
            Assert.False(game.Cell(4, 3).Alive, "This cell should have died");
            Assert.True(game.Cell(5, 3).Alive, "This cell should remain alive");
            Assert.True(game.Cell(2, 4).Alive, "This cell should remain alive");
            Assert.False(game.Cell(3, 4).Alive, "This cell should have died");
            Assert.False(game.Cell(4, 4).Alive, "This cell should have died");
            Assert.True(game.Cell(5, 4).Alive, "This cell should have come alive");
            Assert.True(game.Cell(3, 5).Alive, "This cell should have come alive");


            //arrange for 2 generations
            game = new Library.Game(5, 5, 2, input); //initialize game with 5x5 board, 2 generations, and given input

            //act
            game.Start();

            //assert that it is back to original state
            Assert.False(game.Cell(4, 2).Alive, "This cell should have died again");
            Assert.False(game.Cell(2, 3).Alive, "This cell should have died again");
            Assert.True(game.Cell(3, 3).Alive, "This cell should have come alive again");
            Assert.True(game.Cell(4, 3).Alive, "This cell should have come alive again");
            Assert.True(game.Cell(5, 3).Alive, "This cell should remain alive");
            Assert.True(game.Cell(2, 4).Alive, "This cell should remain alive");
            Assert.True(game.Cell(3, 4).Alive, "This cell should have come alive again");
            Assert.True(game.Cell(4, 4).Alive, "This cell should have come alive again");
            Assert.False(game.Cell(5, 4).Alive, "This cell should have died again");
            Assert.False(game.Cell(3, 5).Alive, "This cell should have died again");
        }
示例#13
0
        public bool UpdateGame(Library.Game game)
        {
            bool success = true;

            try
            {
                Game gameDB = Mapper.Map(game);
                _db.Entry(_db.Game.Find(gameDB.GameId)).CurrentValues.SetValues(gameDB);
                // _db.Update(gameDB);
                _db.SaveChanges();
                return(success);
            }
            catch
            {
                success = false;
                return(success);
            }
        }
示例#14
0
        public void FourCellBlock_should_remain_static()
        {
            //arrange
            var input = new List <Library.Cell> {
                new Library.Cell(2, 2),
                new Library.Cell(2, 3),
                new Library.Cell(3, 2),
                new Library.Cell(3, 3)
            };

            var game = new Library.Game(4, 4, 1, input); //initialize game with 4x4 board, 1 generation, and given input

            //act
            game.Start();

            //assert
            Assert.True(game.Cell(2, 2).Alive, "This cell should still be alive");
            Assert.True(game.Cell(2, 3).Alive, "This cell should still be alive");
            Assert.True(game.Cell(3, 2).Alive, "This cell should still be alive");
            Assert.True(game.Cell(3, 3).Alive, "This cell should still be alive");
        }
示例#15
0
        public void A_live_cell_more_than_three_live_neighbours_dies()
        {
            //arrange
            //..........
            //..........
            //..........
            //....X.....
            //...XX.....
            //...XX.....
            //..........
            //..........
            //..........
            //..........
            var input = new List <Library.Cell> {
                new Library.Cell(5, 5),
                new Library.Cell(5, 6),
                new Library.Cell(5, 4),
                new Library.Cell(4, 5),
                new Library.Cell(4, 6)
            };

            var game = new Library.Game(10, 10, 1, input); //initialize game with 10x10 board, 1 generation, and given input

            //act
            game.Start();

            //assert
            //..........
            //..........
            //..........
            //....?.....
            //...?......
            //...??.....
            //..........
            //..........
            //..........
            //..........
            Assert.False(game.Cell(5, 5).Alive, "This cell should be dead");
        }
示例#16
0
        internal override bool Handle(PlayerEventCode eventCode, Dictionary <byte, object> parameters, out string errorMessage)
        {
            if (base.Handle(eventCode, parameters, out errorMessage))
            {
                int                gameID              = (int)parameters[(byte)GameStartParameterCode.GameID];
                int                player1ID           = (int)parameters[(byte)GameStartParameterCode.Player1ID];
                string             player1Nickname     = (string)parameters[(byte)GameStartParameterCode.Player1Nickname];
                Library.GamePlayer gamePlayer1         = SerializationHelper.Deserialize <Library.GamePlayer>((byte[])parameters[(byte)GameStartParameterCode.GamePlayer1DataByteArray]);
                int                player2ID           = (int)parameters[(byte)GameStartParameterCode.Player2ID];
                string             player2Nickname     = (string)parameters[(byte)GameStartParameterCode.Player2Nickname];
                Library.GamePlayer gamePlayer2         = SerializationHelper.Deserialize <Library.GamePlayer>((byte[])parameters[(byte)GameStartParameterCode.GamePlayer2DataByteArray]);
                int                roundCount          = (int)parameters[(byte)GameStartParameterCode.RoundCount];
                int                currentGamePlayerID = (int)parameters[(byte)GameStartParameterCode.CurrentGamePlayerID];
                GameCardManager    gameCardManager     = SerializationHelper.Deserialize <GameCardManager>((byte[])parameters[(byte)GameStartParameterCode.GameCardManagerByteArray]);

                gamePlayer1.Player = new Library.Player(player1ID, player1Nickname);
                gamePlayer2.Player = new Library.Player(player2ID, player2Nickname);

                Library.Game game = new Library.Game
                                    (
                    gameID: gameID,
                    gamePlayer1: gamePlayer1,
                    gamePlayer2: gamePlayer2,
                    roundCount: roundCount,
                    currentGamePlayerID: currentGamePlayerID,
                    gameCardManager: gameCardManager
                                    );
                GameManager.Instance.AddGame(game);
                gamePlayer1.BindGame(game);
                gamePlayer2.BindGame(game);
                gameCardManager.BindGame(game);
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#17
0
        public void A_dead_cell_with_exactly_three_live_neighbours_comes_alive()
        {
            //arrange
            //..........
            //..........
            //..........
            //..........
            //....X.....
            //....X.....
            //....X.....
            //..........
            //..........
            //..........
            var input = new List <Library.Cell> {
                new Library.Cell(5, 5),
                new Library.Cell(5, 6),
                new Library.Cell(5, 7)
            };

            var game = new Library.Game(10, 10, 1, input); //initialize game with 10x10 board, 1 generation, and given input

            //act
            game.Start();

            //assert
            //..........
            //..........
            //..........
            //..........
            //....?.....
            //...X?X....
            //....?.....
            //..........
            //..........
            //..........
            Assert.True(game.Cell(4, 6).Alive, "This cell should have come alive");
            Assert.True(game.Cell(6, 6).Alive, "This cell should have come alive");
        }
示例#18
0
        public bool AddGame(Library.Game game)
        {
            bool success = true;

            try
            {
                if (game.Tags == null)
                {
                    return(false);
                }
                var gameDB = Mapper.Map(game);
                _db.Add(gameDB);                //shit
                _db.SaveChanges();
                game.GameId = gameDB.GameId;

                return(success);
            }
            catch
            {
                success = false;
                return(success);
            }
        }
示例#19
0
        public void A_live_cell_with_two_live_neighbours_lives()
        {
            //arrange
            //..........
            //..........
            //..........
            //..........
            //...XX.....
            //....X.....
            //..........
            //..........
            //..........
            //..........
            var input = new List <Library.Cell> {
                new Library.Cell(5, 5),
                new Library.Cell(5, 6),
                new Library.Cell(4, 5)
            };

            var game = new Library.Game(10, 10, 1, input); //initialize game with 10x10 board, 1 generation, and given input

            //act
            game.Start();

            //assert
            //..........
            //..........
            //..........
            //..........
            //...?X.....
            //....?.....
            //..........
            //..........
            //..........
            //..........
            Assert.True(game.Cell(5, 5).Alive, "This cell should be alive");
        }
示例#20
0
        public Library.FullUserGame GetFullUserGame(string username, int id)
        {
            Library.UserGame   titanug   = new Library.UserGame();
            Library.Game       titangame = new Library.Game();
            Library.Developer  titandev  = new Library.Developer();
            List <Library.Dlc> titandlc  = new List <Library.Dlc>();

            titanug   = GetUserGame(username, id);
            titangame = GetGame(id);
            int n = (int)titangame.DeveloperId;

            titandev = GetDeveloper(n);
            titandlc = GetDlcbyUserGame(username, id).ToList();

            Library.FullUserGame titan = new Library.FullUserGame
            {
                Developer = titandev,
                Game      = titangame,
                Dlcs      = titandlc,
                UserGame  = titanug,
            };

            return(titan);
        }
示例#21
0
 static void Main(string[] args)
 {
     Library.Game game = new Library.Game();
 }
示例#22
0
        private GameState GetState(Library.Game game)
        {
            var state = new GameState()
            {
                Name             = game.Name,
                State            = game.State,
                CurrentBet       = game.MinBet,
                PotSize          = game.PotSize,
                SmallBlindAmount = game.BigBlindAmount / 2.0, //todo
                BigBlindAmount   = game.BigBlindAmount,       //todo
                CommunityCards   = new List <Card>(game.GetTableCards().Select(x => new Card(x.Suite, x.Value))),
            };

            foreach (var p in game.Players)
            {
                state.Seats[p.Position] = new Seat()
                {
                    SeatTaken = true,
                    Player    = new PlayerState()
                    {
                        ProfileImage   = p.Avatar,
                        PlayerName     = p.Name,
                        AvailableMoney = p.Chips,
                        CurrentBet     = p.CurrentBet,
                        Folded         = p.Folded,
                        PlayersTurn    = p == game.Current,
                        AllIn          = p.AllIn,
                        IsYou          = false,
                        IsDealer       = p == game.Dealer,
                        PlayerPosition = p.Position,
                        PlayerLost     = game.State == Library.State.DeterminingWinner && p == game.Current
                    },
                };
            }
            for (var i = 0; i < state.Seats.Length; i++)
            {
                if (state.Seats[i] == null)
                {
                    state.Seats[i] = new Seat()
                    {
                        SeatTaken = false
                    };
                }
            }
            state.HandHistory = new List <HandHistory>();
            foreach (var hand in game.HandHistory)
            {
                var         message = hand.PlayerName + " won $" + hand.MoneyWon;
                List <Card> cards   = new List <Card>();
                if (hand.Hand == null)
                {
                    message += ".";
                }
                else
                {
                    message += " with " + GetHandName(hand.Hand.Type) + ".";
                    cards    = hand.Hand.BestCards.Select(x => new Card(x.Suite, x.Value)).ToList();
                }

                state.HandHistory.Add(new HandHistory {
                    Cards = cards, Message = message
                });
            }
            return(state);
        }