Exemple #1
0
        public void GivenASingleStateAndAction_HighestValueAction_ReturnsOnlyAction()
        {
            var values = new ActionValueTable();
            var state  = Board.CreateEmptyBoard();
            var action = new TicTacToeAction();

            values.Set(state, action, 1.0);

            Assert.AreEqual(action, values.HighestValueAction(state));
        }
Exemple #2
0
        public void DuplicateBoards_AreTreatedAsEqual()
        {
            var values      = new ActionValueTable();
            var emptyBoard1 = Board.CreateEmptyBoard();
            var emptyBoard2 = Board.CreateEmptyBoard();
            var action1     = new TicTacToeAction();
            var action2     = new TicTacToeAction();

            values.Set(emptyBoard1, action1, 1.0);
            values.Set(emptyBoard2, action2, 2.0);

            Assert.AreEqual(action2, values.HighestValueAction(emptyBoard1));
            Assert.AreEqual(action2, values.HighestValueAction(emptyBoard2));
        }
Exemple #3
0
        public void HighestValueAction_ReturnsHighestValueAction()
        {
            var values  = new ActionValueTable();
            var state   = Board.CreateEmptyBoard();
            var action0 = new TicTacToeAction();
            var action1 = new TicTacToeAction();
            var action2 = new TicTacToeAction();

            values.Set(state, action0, 0);
            values.Set(state, action1, 1);
            values.Set(state, action2, 2);

            Assert.AreEqual(action2, values.HighestValueAction(state));
        }
Exemple #4
0
        public static void Save(
            ActionValueTable actionValues,
            string agentName,
            string description,
            string path,
            BoardTile tile)
        {
            var s = new SerializableStateActionPolicy(agentName, description, tile);

            foreach (var(board, action) in actionValues.HighestValueActions())
            {
                s.AddStateAction(
                    board,
                    action.Position,
                    actionValues.HighestValue(board));
            }
            File.WriteAllText(path, JsonSerializer.Serialize(s, BuildJsonOptions()));
        }
Exemple #5
0
        public void DuplicateActions_AreTreatedAsEqual()
        {
            var values  = new ActionValueTable();
            var board   = Board.CreateEmptyBoard();
            var action1 = new TicTacToeAction {
                Position = 2, Tile = BoardTile.X
            };
            var action2 = new TicTacToeAction {
                Position = 2, Tile = BoardTile.X
            };

            values.Set(board, action1, 1.0);
            values.Set(board, action2, 2.0);

            var expectedHighestValueAction = new TicTacToeAction {
                Position = 2, Tile = BoardTile.X
            };

            Assert.AreEqual(expectedHighestValueAction, values.HighestValueAction(board));
        }