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); }
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); }
public static GoBoard Undo(GoBoard original, int nbMoves) { var toReturn = original.Clone(true); for (int i = 0; i < nbMoves; i++) { toReturn.Undo(); } return(toReturn); }
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); }
//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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
//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()); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
public static string GTPInfluence(string dataDirectory, GoBoard board) { return(GTPInfluenceByFunction(dataDirectory, board, GetInfluence)); }
// 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); }
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); }
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); }
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); }