Exemplo n.º 1
0
        public void ExecuteMove_auto_plays_all_possible_moves_next()
        {
            /*
             * HH CC DD SS
             * KH TC KD KS
             *
             * aa bb cc dd
             * QC -- -- --
             *
             * 00 01 02 03 04 05 06 07
             * -- -- -- -- -- -- -- --
             * KC
             * JC
             */
            var r     = Reserve.Create("QC");
            var f     = Foundation.Create(Ranks.Rk, Ranks.R10, Ranks.Rk, Ranks.Rk);
            var t0    = Tableau.Create("KC JC");
            var tRest = Tableau.Create();
            var ts    = Tableaus.Create(t0, tRest, tRest, tRest, tRest, tRest, tRest, tRest);
            var b     = Board.Create(r, f, ts);

            Assert.True(b.IsValid());

            // Act
            b = b.ExecuteMove(Move.Get(MoveType.TableauToFoundation, 0));

            // Assert
            Assert.Equal(1, b._manualMoveCount);
            Assert.Equal(2, b.AutoMoveCount);
            Assert.Equal(3, b.MoveCount);
            Assert.True(b.IsSolved);
        }
Exemplo n.º 2
0
        public void Clone_clones_object()
        {
            var ts = Tableaus.Create(
                Tableau.Create(),
                Tableau.Create("KC"),
                Tableau.Create("KD"),
                Tableau.Create("KH"),
                Tableau.Create("KS"),
                Tableau.Create("QC"),
                Tableau.Create("QD"),
                Tableau.Create());
            var clone = ts.CloneX();

            Assert.Equal(ts.EmptyCount(), clone.EmptyCount());
            Assert.Equal(Card.Null, clone[0].Top);
            Assert.Equal(Card.Get("KC"), clone[1].Top);
            Assert.Equal(Card.Get("KD"), clone[2].Top);
            Assert.Equal(Card.Get("KH"), clone[3].Top);
            Assert.Equal(Card.Get("KS"), clone[4].Top);
            Assert.Equal(Card.Get("QC"), clone[5].Top);
            Assert.Equal(Card.Get("QD"), clone[6].Top);
            Assert.Equal(Card.Null, clone[7].Top);

            Assert.NotSame(ts, clone);

            var fi = typeof(Tableau).GetField("_state", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);

            for (var i = 0; i < 8; i++)
            {
                Assert.True(ts[i].Equals(clone[i]));
                Assert.NotSame(ts[i], clone[i]);
                Assert.Equal(ts[i].Top, clone[i].Top);
                Assert.NotSame(fi.GetValue(ts[i]), fi.GetValue(clone[i]));
            }
        }
Exemplo n.º 3
0
        public void GetValue_returns_value_at_specified_index()
        {
            var t = Tableau.Create("5H 9S 2D");

            Assert.Equal(Card.Get("2D").RawValue, t.GetValue(2));
            Assert.Equal(Card.Get("5H").RawValue, t.GetValue(0));
        }
Exemplo n.º 4
0
        public void Indexer_returns_cards_starting_from_bottom()
        {
            var t = Tableau.Create("5H 9S 2D");

            Assert.Equal(Card.Get("2D"), t[2]);
            Assert.Equal(Card.Get("5H"), t[0]);
        }
Exemplo n.º 5
0
        public void Top_returns_top_card_or_null_if_empty()
        {
            var t = Tableau.Create("5H 9S 2D");

            Assert.Equal(Card.Get("2D"), t.Top);

            t = Tableau.Create("");
            Assert.Equal(Card.Null, t.Top);
        }
Exemplo n.º 6
0
        public void Top_is_tracked_when_pushing()
        {
            var t = Tableau.Create("5H");

            Assert.Equal(Card.Get("5H"), t.Top);

            t.Push(Card.Get("4S"));
            Assert.Equal(Card.Get("4S"), t.Top);
        }
Exemplo n.º 7
0
        public void Props_are_properly_initialized(string tableau, int expectedSize, int expectedSortedSize, string expectedTop)
        {
            // Arrange & act
            var t = Tableau.Create(tableau);

            // Assert
            Assert.Equal(expectedSize, t.Size);
            Assert.Equal(expectedSortedSize, t.SortedSize);
            Assert.Equal(Card.Get(expectedTop), t.Top);
        }
Exemplo n.º 8
0
 public void Dump_returns_string_representation()
 => Assert.Equal(
     $"00 01 02 03 04 05 06 07{Environment.NewLine}-- -- -- -- -- -- -- --{Environment.NewLine}   KC KD KH KS QC QD   {Environment.NewLine}      9C               ",
     Tableaus.Create(Tableau.Create(),
                     Tableau.Create("KC"),
                     Tableau.Create("KD 9C"),
                     Tableau.Create("KH"),
                     Tableau.Create("KS"),
                     Tableau.Create("QC"),
                     Tableau.Create("QD"),
                     Tableau.Create("")).Dump());
Exemplo n.º 9
0
        public void Pop_tests()
        {
            // Arrange
            var cards    = "8D 7C 6H 5S 4H 3C 2D";
            var cardsArr = cards.Split(' ').Select(c => Card.Get(c)).ToArray();

            var t = Tableau.Create(cards);

            Assert.Equal(7, t.Size);
            Assert.Equal(7, t.SortedSize);
            Assert.Equal(cardsArr[^ 1], t.Top);
Exemplo n.º 10
0
        public void CanMove_returns_whether_top_can_be_moved_to_foundation()
        {
            // Can't move when empty
            Assert.False(Tableau.Create().CanMove(Foundation.Create()));

            // Can't move when non-empty but no valid foundation target
            Assert.False(Tableau.Create("5H").CanMove(Foundation.Create()));

            // Can move to foundation on top of 4H
            Assert.True(Tableau.Create("5H").CanMove(Foundation.Create(Ranks.R4, Ranks.Nil, Ranks.Nil, Ranks.Nil)));
        }
Exemplo n.º 11
0
        public void Push_pushes_card_to_top_and_maintains_size_and_sortedSize()
        {
            var t = Tableau.Create("8S 2H 9C 8H");

            Assert.Equal(4, t.Size);
            Assert.Equal(2, t.SortedSize);

            t.Push(Card.Get("7C"));
            Assert.Equal(Card.Get("7C"), t.Top);
            Assert.Equal(5, t.Size);
            Assert.Equal(3, t.SortedSize);
        }
Exemplo n.º 12
0
        public void Top_is_tracked_when_popping()
        {
            var t = Tableau.Create("5H 4S");

            Assert.Equal(Card.Get("4S"), t.Top);

            t.Pop();
            Assert.Equal(Card.Get("5H"), t.Top);

            t.Pop();
            Assert.Equal(Card.Null, t.Top);
        }
Exemplo n.º 13
0
        public void State_is_initialized_to_empty_tableau()
        {
            var t = Tableau.Create();

            for (var i = 0; i < 18; i++)
            {
                Assert.Equal(Card.Null, t[i]);
            }

            Assert.Equal(0, t.Size);
            Assert.Equal(0, t.SortedSize);
            Assert.Equal(Card.Null, t.Top);
        }
Exemplo n.º 14
0
        public void Move_moves_card_to_tableau()
        {
            var t = Tableau.Create("5H");
            var r = Reserve.Create("4S");

            r.Move(0, t);

            Assert.Equal(Card.Null, r[0]);
            Assert.Equal(4, r.FreeCount);
            Assert.Equal(2, t.Size);
            Assert.Equal(2, t.SortedSize);
            Assert.Equal(Card.Get("4S"), t.Top);
        }
Exemplo n.º 15
0
        public void EmptyCount_returns_empty_tableau_count()
        {
            var ts = Tableaus.Create(
                Tableau.Create(),
                Tableau.Create("KC"),
                Tableau.Create("KD"),
                Tableau.Create("KH"),
                Tableau.Create("KS"),
                Tableau.Create("QC"),
                Tableau.Create("QD"),
                Tableau.Create());

            Assert.Equal(2, ts.EmptyCount());
        }
Exemplo n.º 16
0
        public void CanMove_returns_whether_top_can_be_moved_to_reserve()
        {
            // Can't move when empty
            Assert.False(Tableau.Create().CanMove(Reserve.Create(), out var idx));
            Assert.Equal(-1, idx);

            // Can't move when non-empty but full reserve
            Assert.False(Tableau.Create("5H").CanMove(Reserve.Create("AC", "AD", "AH", "AS"), out idx));
            Assert.Equal(-1, idx);

            // Can move to reserve slot #2 (index=1)
            Assert.True(Tableau.Create("5H").CanMove(Reserve.Create("AD", null, "AH", "AS"), out idx));
            Assert.Equal(1, idx);
        }
Exemplo n.º 17
0
        public void GetValidMoves_returns_moves_in_correct_order()
        {
            /*
             * HH CC DD SS
             * -- QC KD JS
             *
             * aa bb cc dd
             * KC -- -- --
             *
             * 00 01 02 03 04 05 06 07
             * -- -- -- -- -- -- -- --
             * KS QS    AH
             *          2H
             *          3H
             *          4H
             *          5H
             *          6H
             *          7H
             *          8H
             *          9H
             *          TH
             *          JH
             *          QH
             *          KH
             */
            var r     = Reserve.Create("KC");
            var f     = Foundation.Create(Ranks.Nil, Ranks.Rq, Ranks.Rk, Ranks.Rj);
            var t0    = Tableau.Create("KS");
            var t1    = Tableau.Create("QS");
            var t3    = Tableau.Create("AH 2H 3H 4H 5H 6H 7H 8H 9H TH JH QH KH");
            var tRest = Tableau.Create();
            var ts    = Tableaus.Create(t0, t1, tRest, t3, tRest, tRest, tRest, tRest);
            var b     = Board.Create(r, f, ts);

            Assert.True(b.IsValid());

            // Act
            var moves = b.GetValidMoves();

            // Assert
            Assert.Equal(MoveType.ReserveToFoundation, moves[0].Type);
            Assert.Equal(MoveType.TableauToFoundation, moves[1].Type);
            Assert.Equal(MoveType.ReserveToTableau, moves[2].Type);
            Assert.Equal(MoveType.TableauToTableau, moves[3].Type);
            Assert.Equal(MoveType.TableauToTableau, moves[4].Type);
            Assert.Equal(MoveType.TableauToReserve, moves[5].Type);
            Assert.Equal(MoveType.TableauToReserve, moves[6].Type);
            Assert.Equal(MoveType.TableauToReserve, moves[7].Type);
        }
Exemplo n.º 18
0
        public void Pop_updates_stack_when_col_is_sorted_after_pop_operation()
        {
            // Arrange
            var t = Tableau.Create("TH 9C 7C");

            // Act
            t.Pop();

            // Assert
            Assert.Equal(2, t.Size);
            Assert.Equal(2, t.SortedSize);
            Assert.Equal(Card.Get("9C"), t.Top);
            Assert.Equal(Card.Get("9C"), t[1]);
            Assert.Equal(Card.Get("TH"), t[0]);
        }
Exemplo n.º 19
0
        public void Pop_pops_top_and_maintains_size_and_sortedSize()
        {
            // Arrange
            var t = Tableau.Create("8S 2H 9C 8H");

            Assert.Equal(4, t.Size);
            Assert.Equal(2, t.SortedSize);

            // Act
            t.Pop();

            // Assert
            Assert.Equal(Card.Get("9C"), t.Top);
            Assert.Equal(3, t.Size);
            Assert.Equal(1, t.SortedSize);
        }
        public void GetValidMoves_doesnt_block_TtT_move_when_column_sortSize_changes_after_move()
        {
            /*
             * HH CC DD SS
             * 6H 6C AD 4S
             *
             * 00 01 02 03
             * QH 5D KH KD
             *
             * 00 01 02 03 04 05 06 07
             * -- -- -- -- -- -- -- --
             * KC 2D QC QD 6S 8H TH JD
             * 7D JH    JS QS 8S 9C TS
             * TC             KS 7C 9H
             * 9D             6D 3D
             * 8C             5S 7S
             * 7H             4D JC
             *                   TD
             *                   9S
             *                   8D
             */

            var b = Board.Create(
                Reserve.Create("QH", "5D", "KH", "KD"),
                Foundation.Create(Ranks.R6, Ranks.R6, Ranks.Ace, Ranks.R4),
                Tableaus.Create(
                    Tableau.Create("KC 7D TC 9D 8C 7H"),
                    Tableau.Create("2D JH"),
                    Tableau.Create("QC"),
                    Tableau.Create("QD JS"),
                    Tableau.Create("6S QS"),
                    Tableau.Create("8H 8S KS 6D 5S 4D"),
                    Tableau.Create("TH 9C 7C 3D 7S JC TD 9S 8D"),
                    Tableau.Create("JD TS 9H")
                    )
                );

            Assert.True(b.IsValid());
            b = b.ExecuteMove(Move.Get(MoveType.TableauToTableau, 1, 2));

            // Act
            var moves    = b.GetValidMoves().ToArray();
            var tttMoves = moves.Where(p => p.Type == MoveType.TableauToTableau).ToList();

            // Assert
            Assert.Single(tttMoves.Where(m => m.From == 2 && m.To == 1 && m.Size == 1));
        }
Exemplo n.º 21
0
        public void GetValidMoves_returns_all_valid_tf_moves()
        {
            /*
             * HH CC DD SS
             * -- 3C 3D --
             *
             * aa bb cc dd
             * -- -- -- --
             *
             * 00 01 02 03 04 05 06 07
             * -- -- -- -- -- -- -- --
             * QD QC KC 2S 5H JH KD 5C
             * 3H JD JS 6H QS 6D 8D 9C
             * TD JC 8C 6C 8S 4S 5D QH
             * 7S 9D KS AS 6S 4H KH 8H
             * AH 9S TC 7C 3S TS 9H 2H
             * 5S    7H    4C    4D 7D
             *       TH
             *             ^     ^
             *             |     |
             *       should pick these 2
             */

            // Arrange
            var r  = Reserve.Create();
            var f  = Foundation.Create(Ranks.Nil, Ranks.R3, Ranks.R3, Ranks.Nil);
            var t0 = Tableau.Create("QD 3H TD 7S AH 5S");
            var t1 = Tableau.Create("QC JD JC 9D 9S");
            var t2 = Tableau.Create("KC JS 8C KS TC 7H TH");
            var t3 = Tableau.Create("2S 6H 6C AS 7C");
            var t4 = Tableau.Create("5H QS 8S 6S 3S 4C");
            var t5 = Tableau.Create("JH 6D 4S 4H TS");
            var t6 = Tableau.Create("KD 8D 5D KH 9H 4D");
            var t7 = Tableau.Create("5C 9C QH 8H 2H 7D");
            var ts = Tableaus.Create(t0, t1, t2, t3, t4, t5, t6, t7);
            var b  = Board.Create(r, f, ts);

            Assert.True(b.IsValid());

            // Act
            var moves = b.GetValidMoves().ToArray();

            // Assert
            Assert.Equal(2, moves.Where(m => m.Type == MoveType.TableauToFoundation).Count());
            Assert.Equal(Move.Get(MoveType.TableauToFoundation, 4), moves[0]);
            Assert.Equal(Move.Get(MoveType.TableauToFoundation, 6), moves[1]);
        }
Exemplo n.º 22
0
        public void GetValidMoves_skips_partial_moves_of_sorted_tableau_to_empty_one()
        {
            /*
             * HH CC DD SS
             * 2H 4C 6D 8S
             *
             * aa bb cc dd
             * KS 6H KD --
             *
             * 00 01 02 03 04 05 06 07
             * -- -- -- -- -- -- -- --
             * JC    QS JS 9S JH 5C
             * TH    QC 8C TC 9D 6C
             * 9C    TS 3H KC 9H QH
             *       7C 7H JD 8H 8D
             *       KH 7D    4H TD
             *                   QD
             *                   5H
             *
             * Max allowed: 4
             * Valid moves: 2->1(1), 3->1(1), 4->1(1), 5->1(1), 6->1(1)
             */

            // Arrange
            var r     = Reserve.Create("KS", "6H", "KD");
            var f     = Foundation.Create(Ranks.R2, Ranks.R4, Ranks.R6, Ranks.R8);
            var t0    = Tableau.Create("JC TH 9C");
            var t2    = Tableau.Create("QS QC TS 7C KH");
            var t3    = Tableau.Create("JS 8C 3H 7H 7D");
            var t4    = Tableau.Create("9S TC KC JD");
            var t5    = Tableau.Create("JH 9D 9H 8H 4H");
            var t6    = Tableau.Create("5C 6C QH 8D TD QD 5H");
            var tRest = Tableau.Create();
            var ts    = Tableaus.Create(t0, tRest, t2, t3, t4, t5, t6, tRest);
            var b     = Board.Create(r, f, ts);

            Assert.True(b.IsValid());

            // Act
            var moves = b.GetValidMoves().ToArray();

            // Assert
            Assert.Equal(5, moves.Where(m => m.Type == MoveType.TableauToTableau).Count());
            Assert.Empty(moves.Where(m => m.Type == MoveType.TableauToTableau && m.From == 0 && m.To == 1));
            Assert.All(moves.Where(m => m.Type == MoveType.TableauToTableau), m => Assert.True(m.To == 1));
        }
Exemplo n.º 23
0
        public void AllCards_returns_all_cards()
        {
            var t0       = Tableau.Create("AC");
            var t1       = Tableau.Create("AD");
            var t3       = Tableau.Create("AH AS");
            var ts       = Tableaus.Create(t0, t1, Tableau.Create(), t3);
            var allCards = ts.AllCards().ToList();

            // Assert
            Assert.Equal(4, allCards.Count);
            Assert.Equal(Card.Get("AC"), allCards[0]);
            Assert.Equal(Card.Get("AD"), allCards[1]);
            Assert.Equal(Card.Get("AH"), allCards[2]);
            Assert.Equal(Card.Get("AS"), allCards[3]);

            Assert.Empty(Tableaus.Create().AllCards());
        }
        public void GetValidMoves_unblocks_reverse_moves_TtT_when_original_tableaus_had_any_manual_moves()
        {
            /*
             * HH CC DD SS
             * 2H 4C 6D 8S
             *
             * aa bb cc dd
             * KS 6H KD JD
             *
             * 00 01 02 03 04 05 06 07
             * -- -- -- -- -- -- -- --
             * 9S    QS JS    JH 5C
             * QD    QC 8C    9D 6C
             * 7D    TS 3H    9H QH
             * TC    7C 7H    8H 8D
             * JC    KH KC    4H 5H
             * TH                TD
             * 9C
             */

            // Arrange
            var r     = Reserve.Create("KS", "6H", "KD", "JD");
            var f     = Foundation.Create(Ranks.R2, Ranks.R4, Ranks.R6, Ranks.R8);
            var t0    = Tableau.Create("9S QD 7D TC JC TH 9C");
            var t2    = Tableau.Create("QS QC TS 7C KH");
            var t3    = Tableau.Create("JS 8C 3H 7H KC");
            var t5    = Tableau.Create("JH 9D 9H 8H 4H");
            var t6    = Tableau.Create("5C 6C QH 8D 5H TD");
            var tRest = Tableau.Create();
            var ts    = Tableaus.Create(t0, tRest, t2, t3, tRest, t5, t6, tRest);
            var b     = Board.Create(r, f, ts);

            Assert.True(b.IsValid());

            b = b.ExecuteMove(Move.Get(MoveType.TableauToTableau, 0, 6));
            b = b.ExecuteMove(Move.Get(MoveType.TableauToTableau, 0, 1));
            b = b.ExecuteMove(Move.Get(MoveType.TableauToTableau, 6, 7));

            // Act
            var moves    = b.GetValidMoves().ToArray();
            var tttMoves = moves.Where(p => p.Type == MoveType.TableauToTableau).ToList();

            // Assert
            Assert.Single(tttMoves.Where(m => m.From == 6 && m.To == 0));
        }
Exemplo n.º 25
0
        public void GetValidMoves_calculates_maxMoveSize_correctly()
        {
            /*
             * HH CC DD SS
             * 2H 4C 6D 8S
             *
             * aa bb cc dd
             * QS 6H TH JD
             *
             * 00 01 02 03 04 05 06 07
             * -- -- -- -- -- -- -- --
             * 9S JC KD JS KS 9C 5C 5H
             * QD    KH 8C    9D 6C
             * 7D    JH 3H    9H QH
             * TC    TS 7H    8H 8D
             *          KC    4H TD
             *          7C    QC
             *       ^        ^
             *       |        |
             *       |        |
             *       ----------
             *        JH,TS - Can't move since available is 1 and move size is 2
             */
            var r     = Reserve.Create("QS", "6H", "TH", "JD");
            var f     = Foundation.Create(Ranks.R2, Ranks.R4, Ranks.R6, Ranks.R8);
            var t0    = Tableau.Create("9S QD 7D TC");
            var t1    = Tableau.Create("JC");
            var t2    = Tableau.Create("KD KH JH TS");
            var t3    = Tableau.Create("JS 8C 3H 7H KC 7C");
            var t4    = Tableau.Create("KS");
            var t5    = Tableau.Create("9C 9D 9H 8H 4H QC");
            var t6    = Tableau.Create("5C 6C QH 8D TD");
            var t7    = Tableau.Create("5H");
            var tRest = Tableau.Create();
            var ts    = Tableaus.Create(t0, t1, t2, t3, t4, t5, t6, t7);
            var b     = Board.Create(r, f, ts);

            Assert.True(b.IsValid());

            // Act
            var moves = b.GetValidMoves().ToArray();

            // Assert
            Assert.Empty(moves.Where(m => m.Type == MoveType.TableauToTableau && m.From == 2 && m.To == 5 && m.Size == 2));
        }
Exemplo n.º 26
0
        public void GetValidMoves_skips_similar_moves_from_tableau_to_multiple_empty_tableaus()
        {
            /*
             * HH CC DD SS
             * 2H 4C 6D 8S
             *
             * aa bb cc dd
             * KS 6H KD JD
             *
             * 00 01 02 03 04 05 06 07
             * -- -- -- -- -- -- -- --
             * 9S    QS JS    JH 5C
             * TC    QC 8C    9D 6C
             * KC    TS 3H    9H QH
             * QD    7C 7H    8H 8D
             * JC    KH 7D    4H TD
             * TH                5H
             * 9C
             *
             * Max allowed: 4
             * Possible to move 5 from 0 to 1 but should only move 4, 3, 2, 1 stack(s)
             * Valid moves: 0->1(4), 2->1(1), 3->1(1), 5->1(1), 6->1(1)
             */

            // Arrange
            var r     = Reserve.Create("KS", "6H", "KD", "JD");
            var f     = Foundation.Create(Ranks.R2, Ranks.R4, Ranks.R6, Ranks.R8);
            var t0    = Tableau.Create("9S TC KC QD JC TH 9C");
            var t2    = Tableau.Create("QS QC TS 7C KH");
            var t3    = Tableau.Create("JS 8C 3H 7H 7D");
            var t5    = Tableau.Create("JH 9D 9H 8H 4H");
            var t6    = Tableau.Create("5C 6C QH 8D TD 5H");
            var tRest = Tableau.Create();
            var ts    = Tableaus.Create(t0, tRest, t2, t3, tRest, t5, t6, tRest);
            var b     = Board.Create(r, f, ts);

            Assert.True(b.IsValid());

            // Act
            var moves = b.GetValidMoves().ToArray();

            // Assert
            Assert.Equal(5, moves.Where(m => m.Type == MoveType.TableauToTableau).Count());
            Assert.All(moves.Where(m => m.Type == MoveType.TableauToTableau), m => Assert.True(m.To == 1));
        }
Exemplo n.º 27
0
        public void GetValidMoves_skips_super_moves_when_not_enough_space_to_carry_move()
        {
            /*
             * HH CC DD SS
             * 2H 4C 6D 8S
             *
             * aa bb cc dd
             * QS 6H TH JD
             *
             * 00 01 02 03 04 05 06 07
             * -- -- -- -- -- -- -- --
             * 9S JC KH JS    9C 5C 5H
             * QD    QC 8C    9D 6C
             * 7D    JH 3H    9H QH
             * TC    TS 7H    8H 8D
             *          KC    4H TD
             *          7C    KS
             *       ^        KD
             *       |        ^
             *       |        |
             *       ----------
             *        QC,JH,TS - Can't move since available is 2 and move size is 3
             */
            var r     = Reserve.Create("QS", "6H", "TH", "JD");
            var f     = Foundation.Create(Ranks.R2, Ranks.R4, Ranks.R6, Ranks.R8);
            var t0    = Tableau.Create("9S QD 7D TC");
            var t1    = Tableau.Create("JC");
            var t2    = Tableau.Create("KH QC JH TS");
            var t3    = Tableau.Create("JS 8C 3H 7H KC 7C");
            var t5    = Tableau.Create("9C 9D 9H 8H 4H KS KD");
            var t6    = Tableau.Create("5C 6C QH 8D TD");
            var t7    = Tableau.Create("5H");
            var tRest = Tableau.Create();
            var ts    = Tableaus.Create(t0, t1, t2, t3, tRest, t5, t6, t7);
            var b     = Board.Create(r, f, ts);

            Assert.True(b.IsValid());

            // Act
            var moves = b.GetValidMoves().ToArray();

            // Assert
            Assert.Empty(moves.Where(m => m.Type == MoveType.TableauToTableau && m.From == 2 && m.To == 5 && m.Size == 3));
        }
Exemplo n.º 28
0
        public void ComputeCost_computes_cost()
        {
            /*
             * HH CC DD SS
             * 3H -- -- 2S              colorDiff       = abs(0 + 2 - 0 - 3)            = 1
             *                          movesEstimated  = 52 - (0 + 0 + 3 + 2) = 47 * 2 = 94
             * aa bb cc dd
             * QC -- -- 9D              occupied        = 4 - 2                         = 2
             *
             * 00 01 02 03 04 05 06 07  unsorted_size                                   = 17
             * -- -- -- -- -- -- -- --
             * KC 5D TS 3S 9C TH 4D QD  num_buried                                      = 11
             * QH AC 7H 5S 4S 7S 5C JS
             *    2D 8H 4H JC 6D AD TD
             *    KS    3C JH    9S
             *    KH       8S    8D
             *    6S       KD    7C
             *    4C       QS    6H
             *    3D       JD
             *    2C       TC
             *             9H
             *             8C
             *             7D
             *             6C
             *             5H
             */
            var r  = Reserve.Create("QC", null, null, "9D");
            var f  = Foundation.Create(Ranks.R3, Ranks.Nil, Ranks.Nil, Ranks.R2);
            var t0 = Tableau.Create("KC QH");                                      // unsorted = 0, buried = 0
            var t1 = Tableau.Create("5D AC 2D KS KH 6S 4C 3D 2C AD");              // unsorted = 6, buried = 8 -> 8 for (AC), (AD) is within sorted stack so it wont be counted
            var t2 = Tableau.Create("TS 7H 8H");                                   // unsorted = 2, buried = 0
            var t3 = Tableau.Create("3S 5S 4H 3C");                                // unsorted = 1, buried = 3 -> 3 for (3S), (4H) is within sorted stack so it wont be counted
            var t4 = Tableau.Create("9C 4S JC JH 8S KD QS JD TC 9H 8C 7D 6C 5H");  // unsorted = 5, buried = 0
            var t5 = Tableau.Create("TH 7S 6D");                                   // unsorted = 1, buried = 0
            var t6 = Tableau.Create("4D 5C 9S 8D 7C 6H");                          // unsorted = 2, buried = 0
            var t7 = Tableau.Create("QD JS TD");                                   // unsorted = 0, buried = 0
            var ts = Tableaus.Create(t0, t1, t2, t3, t4, t5, t6, t7);
            var b  = Board.Create(r, f, ts);

            Assert.True(b.IsValid());

            b.ComputeCost();
            Assert.Equal(125, b._cost);
        }
Exemplo n.º 29
0
        public void Board_should_be_equal_when_same_reserve_but_different_order()
        {
            /*
             * HH CC DD SS               |    HH CC DD SS
             * 2H 4C 6D 8S               |    2H 4C 6D 8S
             *                           |
             * aa bb cc dd               |    aa bb cc dd
             * -- 6H -- JD               |    6H JD -- --
             *                           |
             * 00 01 02 03 04 05 06 07   |    00 01 02 03 04 05 06 07
             * -- -- -- -- -- -- -- --   |    -- -- -- -- -- -- -- --
             * 9S KS QS JS KD JH 5C      |    9S KS QS JS KD JH 5C
             * QD    QC 8C    9D 6C      |    QD    QC 8C    9D 6C
             * 7D    TS 3H    9H QH      |    7D    TS 3H    9H QH
             * TC    7C 7H    8H 8D      |    TC    7C 7H    8H 8D
             * JC    KH KC    4H 5H      |    JC    KH KC    4H 5H
             * TH                TD      |    TH                TD
             * 9C                        |                      9C
             */

            // Arrange
            var r     = Reserve.Create(null, "6H", null, "JD");
            var f     = Foundation.Create(Ranks.R2, Ranks.R4, Ranks.R6, Ranks.R8);
            var t0    = Tableau.Create("9S QD 7D TC JC TH 9C");
            var t1    = Tableau.Create("KS");
            var t2    = Tableau.Create("QS QC TS 7C KH");
            var t3    = Tableau.Create("JS 8C 3H 7H KC");
            var t4    = Tableau.Create("KD");
            var t5    = Tableau.Create("JH 9D 9H 8H 4H");
            var t6    = Tableau.Create("5C 6C QH 8D 5H TD");
            var tRest = Tableau.Create();
            var ts    = Tableaus.Create(t0, t1, t2, t3, t4, t5, t6, tRest);
            var b1    = Board.Create(r, f, ts);

            Assert.True(b1.IsValid());

            r = Reserve.Create("6H", "JD");
            var b2 = Board.Create(r, f, ts);

            Assert.True(b2.IsValid());

            Assert.True(b1 == b2);
            Assert.True(b1.GetHashCode() == b2.GetHashCode());
        }
        public void GetValidMoves_blocks_non_meaningfull_RtT_moves_when_last_move_is_TtT()
        {
            /*
             * HH CC DD SS
             * 4H 4C 4D 4S
             *
             * aa bb cc dd
             * 6D 9S -- --
             *
             * 00 01 02 03 04 05 06 07
             * -- -- -- -- -- -- -- --
             * KS KH KD 6C 5C 5S 6S 5H
             * JC JS JH JD QC 6H QH 5D
             * 7D 7H 9H 9D 9C QS TH KC
             * 8D 8H 8S 8C TD TS 7S QD
             *     ↑              ↓ TC
             *     ↑              ↓ 7C
             *     ←←←←←←←←←←←←←←←←
             */

            // Arrange
            var b = Board.Create(Reserve.Create("6D", "9S"), Foundation.Create(Ranks.R4, Ranks.R4, Ranks.R4, Ranks.R4), Tableaus.Create(
                                     Tableau.Create("KS JC 7D 8D"),
                                     Tableau.Create("KH JS 7H 8H"),
                                     Tableau.Create("KD JH 9H 8S"),
                                     Tableau.Create("6C JD 9D 8C"),
                                     Tableau.Create("5C QC 9C TD"),
                                     Tableau.Create("5S 6H QS TS"),
                                     Tableau.Create("6S QH TH 7S"),
                                     Tableau.Create("5H 5D KC QD TC 7C")));

            Assert.True(b.IsValid());
            b = b.ExecuteMove(Move.Get(MoveType.TableauToTableau, 6, 1, 1), false);

            // Act
            var moves    = b.GetValidMoves().ToArray();
            var rttMoves = moves.Where(p => p.Type == MoveType.ReserveToTableau).ToList();

            // Assert
            Assert.Equal(2, rttMoves.Count);
            Assert.Equal(Move.Get(MoveType.ReserveToTableau, 0, 1, 1), rttMoves[0]);
            Assert.Equal(Move.Get(MoveType.ReserveToTableau, 1, 6, 1), rttMoves[1]);
        }