Example #1
0
 public Entry(Board board, int depth, int score, int percent)
 {
     this.board = board;
     this.depth = depth;
     this.score = score;
     this.percent = percent;
 }
Example #2
0
 public IEnumerable<Entry> Import()
 {
     using (var reader = new BinaryReader(File.OpenRead(filename)))
     {
         // 4
         Version = reader.ReadInt32();
         // 4
         Positions = reader.ReadInt32();
         foreach (var i in Enumerable.Range(0, Positions))
         {
             // 16
             var board = new Board(reader.ReadUInt64(), reader.ReadUInt64(), Color.Black);
             // 20
             var height = reader.ReadInt32();
             // 24
             var prune = reader.ReadInt32();
             // 25
             var wld = reader.ReadBoolean();
             // 26
             var knownSolve = reader.ReadBoolean();
             // 28
             var fillOut = reader.ReadInt16();
             // 30
             var cutoff = reader.ReadInt16();
             // 32
             var heuristic = reader.ReadInt16();
             // 34
             var black = reader.ReadInt16();
             // 36
             var white = reader.ReadInt16();
             // 37
             var set = reader.ReadBoolean();
             // 38
             var assigned = reader.ReadBoolean();
             // 39
             var wldSolved = reader.ReadBoolean();
             // 40
             var fill2 = reader.ReadByte();
             // 48
             var games = new int[] { reader.ReadInt32(), reader.ReadInt32() };
             // 49
             var root = reader.ReadBoolean();
             // 52
             var fill3 = reader.ReadBytes(3);
             yield return new Entry(board, height, heuristic, 72/*new BookData()
             {
                 Height = height,
                 Prune = prune,
                 WLD = wld,
                 KnownSolve = knownSolve,
                 Cutoff = cutoff,
                 HeuristicValue = heuristic,
                 BlackValue = black,
                 WhiteValue = white,
                 Games = games
             }*/);
         }
     }
 }
Example #3
0
        public void CanSaveTwoSuccessors()
        {
            // Arrange
            var start = Board.Start;
            var successors = new Board[] { Board.FromString("---------------------------O*------*O-------*O------------------ *"),
                Board.FromString("---------------------------O*-----OOO-----*O-------------------- *")
            };
            using (var session = SessionFactory.OpenSession())
            using (var tx = session.BeginTransaction())
            {
                var pos = start;
                foreach (var successor in successors)
                {
                    pos.AddSuccessor(successor);
                    successor.AddParent(pos);
                }

                session.Save(pos);
                tx.Commit();
            }

            // Assert
            using (var session = SessionFactory.OpenSession())
            using (var tx = session.BeginTransaction())
            {
                var q = from b in session.Query<Board>()
                        where b.Empty == start.Empty && b.Mover == start.Mover
                        select b;
                var found = q.Single();
                Assert.AreEqual(successors.Count(), found.Successors.Count());
                var successor = found.Successors.First();
                Assert.AreEqual(1, successor.Parents.Count());
                tx.Commit();
            }
        }
Example #4
0
        /// <summary>
        /// Calculates a minimal reflection.
        /// </summary>
        /// <returns>Minimal reflection of this board state.</returns>
        public virtual Board MinimalReflection()
        {
            Board temp = new Board(this.empty.ToUInt64(), this.mover.ToUInt64(), this.color);
            Board result = new Board(this.empty.ToUInt64(), this.mover.ToUInt64(), this.color);

            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    for (int k = 0; k < 2; k++)
                    {
                        if (temp < result)
                            result = temp;

                        temp = temp.FlipVertical();
                    }

                    temp = temp.FlipHorizontal();
                }

                temp = temp.FlipDiagonal();
            }

            return result;
        }
Example #5
0
        /// <summary>
        /// Determines whether this board is equal to another board.
        /// </summary>
        /// <param name="obj">Other board.</param>
        /// <returns>True if boards are equal, false otherwise.</returns>
        public virtual bool Equals(Board board)
        {
            if (board == null)
            {
                return false;
            }

            return board.Empty == this.empty && board.Mover == this.mover;
        }
Example #6
0
 /// <summary>
 /// Adds a successor to this position.
 /// </summary>
 /// <param name="successor"></param>
 public virtual void AddSuccessor(Board successor)
 {
     successors.Add(successor);
 }
Example #7
0
 /// <summary>
 /// Adds a parent to this position.
 /// </summary>
 /// <param name="parent"></param>
 public virtual void AddParent(Board parent)
 {
     parents.Add(parent);
 }