public void addSinglePieceToClusterCorrectLiberties()
        {
            //arrange
            GoBoard testgame = new GoBoard(5);

            Coordinate loc = new Coordinate(3, 3);
            testgame.addPiece(loc, Space.Black);
            PieceCluster simpleCluster = new PieceCluster(loc, Space.Black, testgame);

            Coordinate loc2 = new Coordinate(4, 2);
            testgame.addPiece(loc2, Space.White);

            Coordinate loc3 = new Coordinate(4, 3);
            testgame.addPiece(loc3, Space.Black);
            simpleCluster.piecesAdd(loc3);
            simpleCluster.removeLiberty(loc3);
            simpleCluster.addLibertiesOf(loc3);

            int expected = 5;

            //act
            int actual = simpleCluster.Liberties.Count;

            //assert
            Assert.AreEqual(expected, actual);
        }
Exemple #2
0
        public static List <float> GetInfluence(string dataDirectory, GoBoard board)
        {
            var feature = GetPositionFeature(board);

            var evaluation = EvaluateGoModel(dataDirectory, feature);

            evaluation = evaluation.Select(x => 2 * (x - 0.5F)).ToList();
            return(evaluation);
        }
Exemple #3
0
        public static GoBoard Undo(GoBoard original, int nbMoves)
        {
            var toReturn = original.Clone(true);

            for (int i = 0; i < nbMoves; i++)
            {
                toReturn.Undo();
            }
            return(toReturn);
        }
Exemple #4
0
        public static float GetInfluenceValue(string dataDirectory, GoBoard board, Color playerToMove)
        {
            var toReturn = GetInfluence(dataDirectory, board).Sum();

            if (playerToMove.IsWhite)
            {
                toReturn = -toReturn;
            }
            return((toReturn + 351) * InfluenceFactor);
        }
Exemple #5
0
        //public static List<float> GetStatusInfluence(GoBoard board)
        //{
        //    var feature = GetStatusFeature(board);

        //    //var evaluation = EvaluateGoModel(feature);
        //    var evaluation = feature.Select(x => 2 * (x - 0.5F)).ToList();
        //    return evaluation;
        //}



        public static List <float> GetPositionFeature(GoBoard board)
        {
            var inputList = new List <float>();

            foreach (GoCell lCell in board.Cells)
            {
                var cellColor = GetCellPosition(lCell);
                inputList.Add(cellColor);
            }
            return(inputList);
        }
Exemple #6
0
        public static GoGameInput FromSGF(GoBoard endGame, GoBoard midGame, string gtpStatus)
        {
            var inputList = GetPositionFeature(midGame);
            var labelList = GetStatusFeature(endGame, gtpStatus);

            var toReturn = new GoGameInput();

            toReturn.Labels = labelList.ToArray();
            toReturn.Inputs = inputList.ToArray();
            return(toReturn);
        }
Exemple #7
0
        public static List <int> GetCellIndices(GoBoard board, string statusList)
        {
            var toReturn = new List <int>();
            var matches  = cellRegex.Matches(statusList);

            foreach (Match cellMatch in matches)
            {
                var idx = board.Coord.At(cellMatch.Value);
                toReturn.Add(idx);
            }
            return(toReturn);
        }
Exemple #8
0
        public static List <float> GetStatusFeature(GoBoard board, string gtpStatus)
        {
            var inputList      = new List <float>();
            var objGnugoStatus = new GnuGoStatus(board, gtpStatus);

            foreach (GoCell lCell in board.Cells)
            {
                var cellColor = GetCellStatus(board, lCell, objGnugoStatus);
                inputList.Add(cellColor);
            }

            return(inputList);
        }
Exemple #9
0
        public void AnySizeGoGame()
        {
            //arrange
            GoBoard testgame = new GoBoard(5);
            Coordinate location = new Coordinate(6, 6);
            Space expected = Space.Forbidden;

            //act
            Space actual = testgame.getSpace(location);

            //assert
            Assert.AreEqual(expected, actual);
        }
Exemple #10
0
        public static GoBoard BoardFromSGF(string sgfContent)
        {
            GameRecord    lGameRecord    = new GameRecord();
            SGFCollection lSGFCollection = new SGFCollection();

            lSGFCollection.LoadSGFFromMemory(sgfContent);
            lSGFCollection.RetrieveGame(lGameRecord, 0);



            GoBoard lGoBoard = new GoBoard(19);

            GameRecordBoardAdapter.Apply(lGameRecord, lGoBoard, true);
            return(lGoBoard);
        }
Exemple #11
0
        public void basicClusterContainsSelf()
        {
            //arrange
            GoBoard testgame = new GoBoard(5);
            Coordinate loc = new Coordinate(3, 3);
            testgame.addPiece(loc, Space.Black);
            bool expected = true;

            //act
            PieceCluster simpleCluster = new PieceCluster(loc, Space.Black, testgame);
            bool actual = simpleCluster.Pieces.Contains(loc);

            //assert
            Assert.AreEqual(expected, actual);
        }
Exemple #12
0
        public void basicClusterHasFourLiberties()
        {
            //arrange
            GoBoard testgame = new GoBoard(5);
            Coordinate loc = new Coordinate(3, 3);
            testgame.addPiece(loc, Space.Black);
            int expected = 4;

            //act
            PieceCluster simpleCluster = new PieceCluster(loc, Space.Black, testgame);
            int actual = simpleCluster.Liberties.Count;

            //assert
            Assert.AreEqual(expected, actual);
        }
Exemple #13
0
        //public static string GTPStatusInfluence(GoBoard board)
        //{


        //    return GTPInfluenceByFunction("", board, GetStatusInfluence);
        //}


        public static string GTPInfluenceByFunction(string dataDirectory, GoBoard board, InfluenceFunction infFunc)
        {
            StringBuilder s = new StringBuilder(512);

            var influence = infFunc.Invoke(dataDirectory, board);

            s.Append("INFLUENCE ");
            for (int x = 0; x < board.BoardSize; x++)
            {
                for (int y = 0; y < board.BoardSize; y++)
                {
                    s.AppendFormat("{0} {1} ", board.At(x, y), influence[board.At(x, y)].ToString(CultureInfo.InvariantCulture));
                }
            }

            return(s.ToString());
        }
Exemple #14
0
        public void basicKoDenial()
        {
            //arrange
            GoBoard testgame = new GoBoard(5);
            testgame.addPiece(new Coordinate(3, 3), Space.Black);
            testgame.addPiece(new Coordinate(3, 2), Space.White);
            testgame.addPiece(new Coordinate(2, 2), Space.Black);
            testgame.addPiece(new Coordinate(3, 4), Space.White);
            testgame.addPiece(new Coordinate(1, 3), Space.Black);
            testgame.addPiece(new Coordinate(4, 3), Space.White);
            testgame.addPiece(new Coordinate(2, 4), Space.Black);
            testgame.addPiece(new Coordinate(2, 3), Space.White);
            bool expected = false;

            //act
            bool actual = testgame.addPiece(new Coordinate(3, 3), Space.Black);

            //assert
            Assert.AreEqual(expected, actual);
        }
Exemple #15
0
        public GnuGoStatus(GoBoard board, string gtpStatus)
        {
            var statuses = gtpStatus.Trim('=').Trim(' ').Split('=');

            CellsByStatus = new Dictionary <SafetyFlag, HashSet <int> >();
            var whiteStatusList = statuses[0];
            var whiteIndices    = GetCellIndices(board, whiteStatusList);

            CellsByStatus[WhiteTerritory] = new HashSet <int>(whiteIndices);
            var blackStatusList = statuses[1];
            var blackIndices    = GetCellIndices(board, blackStatusList);

            CellsByStatus[BlackTerritory] = new HashSet <int>(blackIndices);
            var aliveList    = statuses[2];
            var aliveIndices = GetCellIndices(board, aliveList);

            CellsByStatus[SafetyFlag.Alive] = new HashSet <int>(aliveIndices);
            var deadList    = statuses[3];
            var deadIndices = GetCellIndices(board, deadList);

            CellsByStatus[SafetyFlag.Dead] = new HashSet <int>(deadIndices);
        }
Exemple #16
0
        public void CantAddBlackSecond()
        {
            //arrange
            GoBoard testgame = new GoBoard();
            Coordinate locationa = new Coordinate(1, 1);
            Coordinate locationb = new Coordinate(1, 2);
            bool expected = false;
            //act
            testgame.addPiece(locationa, Space.Black);
            bool actual = testgame.addPiece(locationb, Space.Black);

            //assert
            Assert.AreEqual(expected, actual);
        }
Exemple #17
0
        public void libertyUpdatingWithLittleCluster()
        {
            //arrange
            GoBoard testgame = new GoBoard(5);

            Coordinate loc = new Coordinate(3, 3);
            testgame.addPiece(loc, Space.Black);
            PieceCluster black1 = new PieceCluster(loc, Space.Black, testgame);

            Coordinate loc2 = new Coordinate(4, 2);
            testgame.addPiece(loc2, Space.White);
            PieceCluster white1 = new PieceCluster(loc2, Space.White, testgame);

            Coordinate loc3 = new Coordinate(4, 3);
            testgame.addPiece(loc3, Space.Black);

            black1.piecesAdd(loc3);
            black1.removeLiberty(loc3);
            black1.addLibertiesOf(loc3);

            white1.removeLiberty(loc3);

            int expected = 3;

            //act
            int actual = white1.Liberties.Count;

            //assert
            Assert.AreEqual(expected, actual);
        }
Exemple #18
0
        public void libertyUpdatingForSimpleClustersWorks()
        {
            //arrange
            GoBoard testgame = new GoBoard(5);

            Coordinate loc = new Coordinate(3, 3);
            testgame.addPiece(loc, Space.Black);
            PieceCluster simpleCluster = new PieceCluster(loc, Space.Black, testgame);

            Coordinate loc2 = new Coordinate(4, 3);
            testgame.addPiece(loc2, Space.White);
            simpleCluster.removeLiberty(loc2);

            int expected = 3;

            //act

            int actual = simpleCluster.Liberties.Count;

            //assert
            Assert.AreEqual(expected, actual);
        }
Exemple #19
0
        public void BoardCreatesPieceClusters()
        {
            //arrange
            GoBoard testgame = new GoBoard(5);
            Coordinate location = new Coordinate(3, 3);
            testgame.addPiece(location, Space.Black);
            bool expected = true;

            //act
            PieceCluster thiscluster = testgame.getClusterContainingCoordinate(location, Space.Black);
            bool actual = (thiscluster.Pieces.Contains(location));

            //assert
            Assert.AreEqual(expected, actual);
        }
Exemple #20
0
        public void libertyUpdatingWithLittleCluster()
        {
            //arrange
            GoBoard testgame = new GoBoard(5);

            Coordinate loc = new Coordinate(3, 3);
            testgame.addPiece(loc, Space.Black);

            Coordinate loc2 = new Coordinate(4, 2);
            testgame.addPiece(loc2, Space.White);

            Coordinate loc3 = new Coordinate(4, 3);
            testgame.addPiece(loc3, Space.Black);

            PieceCluster white1 = testgame.getClusterContainingCoordinate(loc2, Space.White);

            int expected = 3;

            //act
            int actual = white1.Liberties.Count;

            //assert
            Assert.AreEqual(expected, actual);
        }
Exemple #21
0
        public void edgeClusterCapture()
        {
            //arrange
            GoBoard testgame = new GoBoard(5);
            testgame.addPiece(new Coordinate(3, 3), Space.Black);
            testgame.addPiece(new Coordinate(4, 2), Space.White);
            testgame.addPiece(new Coordinate(4, 3), Space.Black);
            testgame.addPiece(new Coordinate(3, 2), Space.White);
            testgame.addPiece(new Coordinate(2, 2), Space.Black);
            testgame.addPiece(new Coordinate(2, 1), Space.White);
            testgame.addPiece(new Coordinate(3, 1), Space.Black);
            testgame.addPiece(new Coordinate(4, 1), Space.White);
            testgame.addPiece(new Coordinate(5, 2), Space.Black);
            testgame.addPiece(new Coordinate(5, 1), Space.White);
            testgame.addPiece(new Coordinate(3, 1), Space.Black);

            Coordinate location = new Coordinate(4, 1);
            Space expected = Space.Empty;

            //act
            Space actual = testgame.getSpace(location);

            //assert
            Assert.AreEqual(expected, actual);
        }
Exemple #22
0
        public void clusterCombinationLiberties()
        {
            //arrange
            GoBoard testgame = new GoBoard(5);
            testgame.addPiece(new Coordinate(3, 3), Space.Black);
            testgame.addPiece(new Coordinate(4, 2), Space.White);
            testgame.addPiece(new Coordinate(4, 3), Space.Black);
            testgame.addPiece(new Coordinate(3, 2), Space.White);
            testgame.addPiece(new Coordinate(2, 2), Space.Black);
            testgame.addPiece(new Coordinate(2, 1), Space.White);
            testgame.addPiece(new Coordinate(3, 1), Space.Black);
            testgame.addPiece(new Coordinate(4, 1), Space.White);
            testgame.addPiece(new Coordinate(5, 2), Space.Black);
            testgame.addPiece(new Coordinate(5, 1), Space.White);
            testgame.addPiece(new Coordinate(3, 1), Space.Black);
            testgame.addPiece(new Coordinate(2, 4), Space.White);
            testgame.addPiece(new Coordinate(3, 2), Space.Black);

            Coordinate loc = new Coordinate(3, 2);
            PieceCluster bigCluster = testgame.getClusterContainingCoordinate(loc, Space.Black);
            int expected = 7;

            //act
            int actual = bigCluster.Liberties.Count();

            //assert
            Assert.AreEqual(expected, actual);
        }
Exemple #23
0
        public void CantOverlapPieces()
        {
            //arrange
            GoBoard testgame = new GoBoard();
            Coordinate location = new Coordinate(1, 1);
            bool expected = false;

            //act
            testgame.addPiece(location, Space.Black);
            bool actual = testgame.addPiece(location, Space.White);

            //assert
            Assert.AreEqual(expected, actual);
        }
Exemple #24
0
        public void CantAddOutOfBounds()
        {
            //arrange
            GoBoard testgame = new GoBoard();
            Coordinate location = new Coordinate(0, 0);
            bool expected = false;

            //act
            bool actual = testgame.addPiece(location, Space.Black);

            //assert
            Assert.AreEqual(expected, actual);
        }
Exemple #25
0
 public static string GTPInfluence(string dataDirectory, GoBoard board)
 {
     return(GTPInfluenceByFunction(dataDirectory, board, GetInfluence));
 }
Exemple #26
0
        // Factory
        // Create new Group for a given point on the board
        public static GroupInfo CreateGroup(GoBoard board, Vector2 point)
        {
            // Sanity Check: Cannot create group if point is not valid
            if (!board.IsValidPoint(point))
            {
                return(null);
            }

            GroupInfo group = new GroupInfo();

            // Create hash to store all points that have been checked
            HashSet <GoPoint> hash_group = new HashSet <GoPoint>();
            // Create queue to store list of points that need to be checked
            Queue <GoPoint> queue_points = new Queue <GoPoint>();

            int x_curr = (int)point.x;
            int y_curr = (int)point.y;

            // Use initial point to determine the group's State (Empty/Black/White)
            GoPoint point_curr = board.gridPoints[x_curr, y_curr];

            group.groupType = point_curr.PointState;

            // Queue initial point
            queue_points.Enqueue(board.gridPoints[x_curr, y_curr]);
            while (queue_points.Count > 0)
            {
                // Retrieve next point
                point_curr = queue_points.Dequeue();
                x_curr     = (int)point_curr.PointBoard.x;
                y_curr     = (int)point_curr.PointBoard.y;

                bool b_state_same = false;

                // Only proceed if we haven't seen this point yet
                if (!hash_group.Contains(point_curr))
                {
                    // Check current point is the same state as our Group
                    if (point_curr.PointState == group.GroupType)
                    {
                        b_state_same = true;
                    }
                }

                // If same, then we want to add it to our Group and check adjacent points
                if (b_state_same)
                {
                    // Add Point to Group
                    group.GroupPoints.Add(point_curr.PointBoard);

                    // Retrieve adjacent points if allied
                    List <Vector2> list_adj = board.GetAdjacentPoints(point_curr.PointBoard);
                    foreach (Vector2 point_adj in list_adj)
                    {
                        queue_points.Enqueue(board.gridPoints[(int)point_adj.x, (int)point_adj.y]);
                    }
                }

                // Mark GoPoint as checked
                hash_group.Add(point_curr);
            }

            // If our Group's type is not territory, check for liberties
            if (group.GroupType != GoColor.GC_Empty)
            {
                foreach (Vector2 gp_curr in group.GroupPoints)
                {
                    List <Vector2> points_adj = board.GetAdjacentPoints(gp_curr);
                    foreach (Vector2 point_adj in points_adj)
                    {
                        if (board.GetPoint(point_adj).IsEmpty())
                        {
                            group.groupLiberties.Add(point_adj);
                        }
                    }
                }
            }

            return(group);
        }
Exemple #27
0
        public static float GetCellStatus(GoBoard lGoBoard, GoCell lCell, GnuGoStatus objGnugoStatus)
        {
            float        toReturn      = 0.5F;
            SafetyStatus lSafetyStatus = lGoBoard.GetSafetyStatus(lCell.Index);

            if (!lSafetyStatus.IsUndecided)
            {
                if (lSafetyStatus.IsBlack)
                {
                    toReturn = 1;
                }
                else if (lSafetyStatus.IsWhite)
                {
                    toReturn = 0;
                }
                if (lSafetyStatus.IsDead)
                {
                    toReturn = 1 - toReturn;
                }
            }
            else
            {
                if (lCell.Color == Color.Black)
                {
                    //if (lGoBoard.GetBlockLibertyCount(lCell.Index) > 1)
                    if (objGnugoStatus.CellsByStatus[SafetyFlag.Dead].Contains(lCell.Index))
                    {
                        toReturn = 0;
                    }
                    else
                    {
                        toReturn = 1;
                    }
                }
                else if (lCell.Color == Color.White)
                {
                    //if (lGoBoard.GetBlockLibertyCount(lCell.Index) > 1)
                    if (objGnugoStatus.CellsByStatus[SafetyFlag.Dead].Contains(lCell.Index))
                    {
                        toReturn = 1;
                    }
                    else
                    {
                        toReturn = 0;
                    }
                }
                else
                {
                    if (objGnugoStatus.CellsByStatus[GnuGoStatus.BlackTerritory].Contains(lCell.Index))
                    {
                        toReturn = 1;
                    }
                    else if (objGnugoStatus.CellsByStatus[GnuGoStatus.WhiteTerritory].Contains(lCell.Index))
                    {
                        toReturn = 0;
                    }
                    else
                    {
                        foreach (int cellIdx in ((GoEmptyBlock)(lCell.Block)).MemberList)
                        {
                            if (objGnugoStatus.CellsByStatus[GnuGoStatus.BlackTerritory].Contains(cellIdx))
                            {
                                toReturn = 1;
                                break;
                            }
                            else if (objGnugoStatus.CellsByStatus[GnuGoStatus.WhiteTerritory].Contains(cellIdx))
                            {
                                toReturn = 0;
                                break;
                            }
                        }
                    }
                }
            }

            return(toReturn);
        }
Exemple #28
0
        public void enemyNeighborHasLessLiberties()
        {
            //arrange
            GoBoard testgame = new GoBoard(5);
            Coordinate loc = new Coordinate(3, 3);
            testgame.addPiece(loc, Space.Black);
            Coordinate loc2 = new Coordinate(4,3);
            testgame.addPiece(loc2, Space.White);
            int expected = 3;

            //act
            PieceCluster simpleCluster = new PieceCluster(loc2, Space.White, testgame);
            int actual = simpleCluster.Liberties.Count;

            //assert
            Assert.AreEqual(expected, actual);
        }
Exemple #29
0
        public void CantAddForbiddenPieces()
        {
            //arrange
            GoBoard testgame = new GoBoard();
            Coordinate location = new Coordinate(1, 1);
            bool expected = false;

            //act
            bool actual = testgame.addPiece(location, Space.Forbidden);

            //assert
            Assert.AreEqual(expected, actual);
        }