// Check if the last recorded game has been a personal record
        static public List <PlayerPersonalRecord> GetLastGameRecords(List <GameSessionHistory> games, int last_game)
        {
            List <PlayerPersonalRecord> records = new List <PlayerPersonalRecord> ();
            GameSessionHistory          higher;

            // We can start to talk about personal records after 5 plays
            if (last_game == -1 || games.Count < MIN_GAMES_RECORD)
            {
                return(records);
            }

            higher = new GameSessionHistory();

            // Find the higher record for every type of game
            for (int i = 0; i < last_game; i++)
            {
                if (games[i].LogicScore > higher.LogicScore)
                {
                    higher.LogicScore = games[i].LogicScore;
                }

                if (games[i].MathScore > higher.MathScore)
                {
                    higher.MathScore = games[i].MathScore;
                }

                if (games[i].MemoryScore > higher.MemoryScore)
                {
                    higher.MemoryScore = games[i].MemoryScore;
                }

                if (games[i].VerbalScore > higher.VerbalScore)
                {
                    higher.VerbalScore = games[i].VerbalScore;
                }
            }

            // It is a record?
            if (games[last_game].LogicScore > higher.LogicScore)
            {
                records.Add(new PlayerPersonalRecord(GameTypes.LogicPuzzle, higher.LogicScore, games[last_game].LogicScore));
            }

            if (games[last_game].MathScore > higher.MathScore)
            {
                records.Add(new PlayerPersonalRecord(GameTypes.Calculation, higher.MathScore, games[last_game].MathScore));
            }

            if (games[last_game].MemoryScore > higher.MemoryScore)
            {
                records.Add(new PlayerPersonalRecord(GameTypes.Memory, higher.MemoryScore, games[last_game].MemoryScore));
            }

            if (games[last_game].VerbalScore > higher.VerbalScore)
            {
                records.Add(new PlayerPersonalRecord(GameTypes.VerbalAnalogy, higher.VerbalScore, games[last_game].VerbalScore));
            }

            return(records);
        }
        public void MinGamesRecord()
        {
            PlayerHistory history;

            GameSessionHistory game = new GameSessionHistory ();
            game.GamesPlayed = Preferences.Get <int> (Preferences.MinPlayedGamesKey);

            history = new PlayerHistory ();
            history.ConfigPath = ".";
            history.Clean ();

            for (int i = 0; i < PlayerPersonalRecord.MIN_GAMES_RECORD - 2; i++)
            {
                history.SaveGameSession (game);
            }

            game.LogicScore = 10;
            history.SaveGameSession (game);

            Assert.AreEqual (0, history.GetLastGameRecords ().Count,
                "Did not reach MinPlayedGamesKey, the game should not be a person record yet");

            game.LogicScore = 30;
            history.SaveGameSession (game);

            Assert.AreEqual (1, history.GetLastGameRecords ().Count,
                "We have just recorded a personal record");

            game.LogicScore = 20;
            history.SaveGameSession (game);

            Assert.AreEqual (0, history.GetLastGameRecords ().Count,
                "Score saved was lower than previous, no record");
        }
Exemple #3
0
        // Deep copy
        public GameSessionHistory Copy()
        {
            GameSessionHistory history = new GameSessionHistory();

            history.GamesPlayed = GamesPlayed;
            history.GamesWon    = GamesWon;
            history.TotalScore  = TotalScore;
            history.MathScore   = MathScore;
            history.LogicScore  = LogicScore;
            history.MemoryScore = MemoryScore;
            history.VerbalScore = VerbalScore;
            return(history);
        }
        public void MinGamesNotReached()
        {
            PlayerHistory history = new PlayerHistory () { ConfigPath = "." };
            GameSessionHistory game = new GameSessionHistory () { GamesPlayed = Preferences.Get <int> (Preferences.MinPlayedGamesKey) };

            history.Clean ();
            for (int i = 0; i < PlayerPersonalRecord.MIN_GAMES_RECORD - 2; i++)
            {
                history.SaveGameSession (game);
            }

            game.LogicScore = 10;
            history.SaveGameSession (game);

            Assert.AreEqual (0, history.GetLastGameRecords ().Count,
                "Did not reach MinPlayedGamesKey, the game should not be a personal record yet");
        }
Exemple #5
0
        public void SaveGameSession(GameSessionHistory score)
        {
            if (score.GamesPlayed < Preferences.Get <int> (Preferences.MinPlayedGamesKey))
            {
                last_game = -1;
                return;
            }

            if (Games.Count >= Preferences.Get <int> (Preferences.MaxStoredGamesKey))
            {
                Games.RemoveAt(0);
            }

            // Storing a copy to allow the input object to be modified
            Games.Add(score.Copy());
            last_game = Games.Count - 1;
            Save();
        }
        public void PersonalRecordDone()
        {
            PlayerHistory history = new PlayerHistory () { ConfigPath = "." };
            GameSessionHistory game = new GameSessionHistory () { GamesPlayed = Preferences.Get <int> (Preferences.MinPlayedGamesKey) };

            history.Clean ();
            for (int i = 0; i < PlayerPersonalRecord.MIN_GAMES_RECORD - 1; i++)
            {
                history.SaveGameSession (game);
            }

            game.LogicScore = 20;
            history.SaveGameSession (game);

            game.LogicScore = 30;
            history.SaveGameSession (game);

            Assert.AreEqual (1, history.GetLastGameRecords ().Count, "We have just recorded a personal record");
        }
        // Check if the last recorded game has been a personal record
        public static List<PlayerPersonalRecord> GetLastGameRecords(List <GameSessionHistory> games, int last_game)
        {
            List <PlayerPersonalRecord> records = new List <PlayerPersonalRecord> ();
            GameSessionHistory higher;

            // We can start to talk about personal records after MIN_GAMES_RECORD games played
            if (last_game == -1 || games.Count < MIN_GAMES_RECORD)
                return records;

            higher = new GameSessionHistory ();

            // Find the higher record for every type of game
            for (int i = 0; i < last_game; i++)
            {
                if (games[i].LogicScore > higher.LogicScore)
                    higher.LogicScore = games[i].LogicScore;

                if (games[i].MathScore > higher.MathScore)
                    higher.MathScore = games[i].MathScore;

                if (games[i].MemoryScore > higher.MemoryScore)
                    higher.MemoryScore = games[i].MemoryScore;

                if (games[i].VerbalScore > higher.VerbalScore)
                    higher.VerbalScore = games[i].VerbalScore;
            }

            // It is a record?
            if (higher.LogicScore > 0 && games[last_game].LogicScore > higher.LogicScore)
                records.Add (new PlayerPersonalRecord (GameTypes.LogicPuzzle, higher.LogicScore, games[last_game].LogicScore));

            if (higher.MathScore > 0 && games[last_game].MathScore > higher.MathScore)
                records.Add (new PlayerPersonalRecord (GameTypes.Calculation, higher.MathScore, games[last_game].MathScore));

            if (higher.MemoryScore > 0 && games[last_game].MemoryScore > higher.MemoryScore)
                records.Add (new PlayerPersonalRecord (GameTypes.Memory, higher.MemoryScore, games[last_game].MemoryScore));

            if (higher.VerbalScore > 0  && games[last_game].VerbalScore > higher.VerbalScore)
                records.Add (new PlayerPersonalRecord (GameTypes.VerbalAnalogy, higher.VerbalScore, games[last_game].VerbalScore));

            return records;
        }
        // Deep copy
        public GameSessionHistory Copy()
        {
            GameSessionHistory history = new GameSessionHistory ();

            history.GamesPlayed = GamesPlayed;
            history.GamesWon = GamesWon;
            history.TotalScore = TotalScore;
            history.MathScore = MathScore;
            history.LogicScore = LogicScore;
            history.MemoryScore = MemoryScore;
            history.VerbalScore = VerbalScore;
            return history;
        }
Exemple #9
0
        public void SaveGameSession(GameSessionHistory score)
        {
            if (score.GamesPlayed < Preferences.Get <int> (Preferences.MinPlayedGamesKey)) {
                last_game = -1;
                return;
            }

            if (Games.Count >= Preferences.Get <int> (Preferences.MaxStoredGamesKey))
                Games.RemoveAt (0);

            // Storing a copy to allow the input object to be modified
            Games.Add (score.Copy ());
            last_game = Games.Count - 1;
            Save ();
        }
        public void PersonalRecordDoneButPreviousWas0()
        {
            PlayerHistory history = new PlayerHistory () { ConfigPath = "." };
            GameSessionHistory game = new GameSessionHistory () { GamesPlayed = Preferences.Get <int> (Preferences.MinPlayedGamesKey) };

            history.Clean ();
            for (int i = 0; i < PlayerPersonalRecord.MIN_GAMES_RECORD; i++)
            {
                history.SaveGameSession (game);
            }

            game.LogicScore = 30;
            history.SaveGameSession (game);

            Assert.AreEqual (0, history.GetLastGameRecords ().Count, "No record since previous was 0");
        }
        public void ScoreLowerThanPrevious()
        {
            PlayerHistory history = new PlayerHistory () { ConfigPath = "." };
            GameSessionHistory game = new GameSessionHistory () { GamesPlayed = Preferences.Get <int> (Preferences.MinPlayedGamesKey) };

            history.Clean ();
            for (int i = 0; i < PlayerPersonalRecord.MIN_GAMES_RECORD - 1; i++)
            {
                history.SaveGameSession (game);
            }

            game.LogicScore = 30;
            history.SaveGameSession (game);

            game.LogicScore = 20;
            history.SaveGameSession (game);

            Assert.AreEqual (0, history.GetLastGameRecords ().Count, "Score saved was lower than previous, no record");
        }