Beispiel #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);
        }
        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]));
            }
        }
 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());
        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());
        }
Beispiel #5
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);
        }
        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));
        }
Beispiel #7
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]);
        }
Beispiel #8
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));
        }
        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());
        }
Beispiel #10
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));
        }
        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));
        }
Beispiel #12
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));
        }
Beispiel #13
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());
        }
Beispiel #14
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);
        }
Beispiel #15
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));
        }
Beispiel #16
0
        public void GetValidMoves_includes_super_moves_when_enough_is_available_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    KH JS    9C 5C 5H
             * QD    QC 8C    KS 6C
             * 7D    JH 3H    9H QH
             * TC    TS 7H    8H 8D
             * JC    9D KC    4H TD
             *          7C    KD
             *       ^
             *       |        ^
             *       |        |
             *       ----------
             *       QC,JH,TS,9D - Can move since available is (0+1)<<2=4 and move size is 4
             */
            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 JC");
            var t2    = Tableau.Create("KH QC JH TS 9D");
            var t3    = Tableau.Create("JS 8C 3H 7H KC 7C");
            var t5    = Tableau.Create("9C KS 9H 8H 4H KD");
            var t6    = Tableau.Create("5C 6C QH 8D TD");
            var t7    = Tableau.Create("5H");
            var tRest = Tableau.Create();
            var ts    = Tableaus.Create(t0, tRest, 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.Single(moves.Where(m => m.Type == MoveType.TableauToTableau && m.From == 2 && m.To == 5 && m.Size == 4));
        }
Beispiel #17
0
        public void EqualityTests()
        {
            Assert.False(Board.FromDealNum(5).Equals(new object()));
            Assert.False(Board.FromDealNum(1) == Board.FromDealNum(2));

            var b1 = Board.FromDealNum(5);
            var b2 = Board.FromDealNum(5);

            Assert.True(b1 == b2);

            b1 = b1.ExecuteMove(Move.Get(MoveType.TableauToReserve, 0, 0), false);
            Assert.True(b1 != b2);

            b2 = b2.ExecuteMove(Move.Get(MoveType.TableauToReserve, 0, 0), false);
            Assert.True(b1 == b2);

            b1 = b1.ExecuteMove(Move.Get(MoveType.TableauToFoundation, 1), false);
            Assert.True(b1 != b2);

            b2 = b2.ExecuteMove(Move.Get(MoveType.TableauToFoundation, 1), false);
            Assert.True(b1 == b2);

            b1 = Board.Create(Reserve.Create("AD", "AH"), Foundation.Create(), Tableaus.Create());
            b2 = Board.Create(Reserve.Create("AC", "AS"), Foundation.Create(), Tableaus.Create());
            Assert.True(b1 != b2);

            b1 = Board.Create(Reserve.Create(), Foundation.Create(), Tableaus.Create(Tableau.Create("KH")));
            b2 = Board.Create(Reserve.Create(), Foundation.Create(), Tableaus.Create(Tableau.Create("KH")));
            Assert.True(b1 == b2);

            b1 = Board.Create(Reserve.Create(), Foundation.Create(), Tableaus.Create(Tableau.Create("KH QS")));
            b2 = Board.Create(Reserve.Create(), Foundation.Create(), Tableaus.Create(Tableau.Create("KD QS")));
            Assert.True(b1 != b2);

            b1 = Board.Create(Reserve.Create(), Foundation.Create(), Tableaus.Create(Tableau.Create("KH QS")));
            b2 = Board.Create(Reserve.Create(), Foundation.Create(), Tableaus.Create(Tableau.Create("KD")));
            Assert.True(b1 != b2);

            b1 = Board.Create(Reserve.Create(), Foundation.Create(), Tableaus.Create(Tableau.Create("KH QS")));
            b2 = Board.Create(Reserve.Create(), Foundation.Create(), Tableaus.Create(Tableau.Create("KD TS 9D")));
            Assert.True(b1 != b2);
        }
Beispiel #18
0
        public void GetValidMoves_skips_moves_that_are_reverse_of_last_move_tt_tt()
        {
            /*
             * HH CC DD SS                        HH CC DD SS
             * 2H 4C 6D 8S                        2H 4C 6D 8S
             *
             * aa bb cc dd                        aa bb cc dd
             * KS 6H KD JD                        KS 6H KD JD
             *
             * 00 01 02 03 04 05 06 07    ===\    00 01 02 03 04 05 06 07
             * -- -- -- -- -- -- -- --    ===/    -- -- -- -- -- -- -- --
             * 9S    QS JS    JH 5C               9S    QS JS    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("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));

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

            // Assert
            Assert.Empty(moves.Where(m => m.Type == MoveType.TableauToTableau && m.From == 6 && m.To == 0));
        }
Beispiel #19
0
        public void GetValidMoves_skips_similar_moves_from_reserve_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
             * QD    QC 8C    9D 6C
             * 7D    TS 3H    9H QH
             * TC    7C 7H    8H 8D
             * JC    KH KC    4H TD
             * TH                5H
             * 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 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(4, moves.Where(m => m.Type == MoveType.ReserveToTableau).Count());
            Assert.Equal(4, moves.Where(m => m.Type == MoveType.ReserveToTableau && m.To == 1).Count());
        }
Beispiel #20
0
        public void GetValidMoves_skips_moves_which_are_whole_columns_to_empty_one()
        {
            /*
             * HH CC DD SS
             * 2H 4C 6D 8S
             *
             * aa bb cc dd
             * -- 6H -- JD
             *
             * 00 01 02 03 04 05 06 07
             * -- -- -- -- -- -- -- --
             * 9S    KH JS    9C 5C
             * QD    QC 8C    9D 6C
             * 7D    JH 3H    9H QH
             * TC    TS 7H    8H 8D
             * JC       KC    4H TD
             * TH       7C    KS 5H
             * QS             KD
             */
            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 QS");
            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 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.Empty(moves.Where(m => m.Type == MoveType.TableauToTableau && m.From == 2 && m.Size == 4));
        }
Beispiel #21
0
        public void GetMoves_returns_moves_with_autoPlays_at_the_end()
        {
            // Arrange
            var b = Board.Create(Reserve.Create(), Foundation.Create(Ranks.Rk, Ranks.R9, Ranks.Rk, Ranks.Rk), Tableaus.Create(
                                     Tableau.Create("KC TC QC"),
                                     Tableau.Create("JC")));

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

            // Act
            var moves = b.GetMoves().ToList();

            // Assert
            Assert.Equal(5, moves.Count); // 1 manual, 4 auto
            Assert.Equal(Move.Get(MoveType.TableauToTableau, 0, 2), moves[0]);
            Assert.Equal(Move.Get(MoveType.TableauToFoundation, 0), moves[1]);
            Assert.Equal(Move.Get(MoveType.TableauToFoundation, 1), moves[2]);
            Assert.Equal(Move.Get(MoveType.TableauToFoundation, 2), moves[3]);
            Assert.Equal(Move.Get(MoveType.TableauToFoundation, 0), moves[4]);
        }
Beispiel #22
0
        public void GetMoves_returns_moves_when_all_are_autoPlays()
        {
            // Arrange
            var b = Board.Create(Reserve.Create(), Foundation.Create(Ranks.Rk, Ranks.Rj, Ranks.Rk, Ranks.Rk), Tableaus.Create(Tableau.Create("KC QC")));

            Assert.True(b.IsValid());
            b.RootAutoPlay();

            // Act
            var moves = b.GetMoves().ToList();

            // Assert
            Assert.Equal(2, moves.Count); // 2 auto
            Assert.Equal(Move.Get(MoveType.TableauToFoundation, 0), moves[0]);
            Assert.Equal(Move.Get(MoveType.TableauToFoundation, 0), moves[1]);
        }
        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]);
        }
Beispiel #24
0
 public void IsSolved_returns_whether_board_is_solved()
 {
     Assert.True(Board.Create(Reserve.Create(), Foundation.Create(Ranks.Rk, Ranks.Rk, Ranks.Rk, Ranks.Rk), Tableaus.Create()).IsSolved);
     Assert.False(Board.FromDealNum(1).IsSolved);
 }