/// <summary> /// Converts a game tree /// </summary> /// <param name="tree">SGF game tree</param> /// <returns>Game tree root</returns> private GameTree ConvertTree(SgfGameTree tree) { var boardSizeInt = tree.GetPropertyInSequence("SZ")?.Value <int>() ?? 19; if (boardSizeInt == 0) { boardSizeInt = 19; } GameBoardSize boardSize = new GameBoardSize(boardSizeInt); var converted = ConvertBranch(tree, boardSize); var ruleset = new ChineseRuleset(boardSize); // Post-processing converted.ForAllDescendants((node) => node.Branches, node => { if (node.Parent == null) { node.FillBoardStateOfRoot(boardSize, ruleset); } else { node.FillBoardState(ruleset); } }); var gameTree = new GameTree(new ChineseRuleset(boardSize), boardSize, converted); gameTree.LastNode = gameTree.GameTreeRoot; return(gameTree); }
/// <summary> /// Checks if the move is pass move /// </summary> /// <param name="gameBoardSize">Size of the game board</param> /// <returns>Is pass?</returns> public bool IsPass(GameBoardSize gameBoardSize) { if (gameBoardSize.Width <= 19 && gameBoardSize.Height <= 19) { var tValue = PointCharToValue('t'); return(Column == tValue && Row == tValue); } return(IsInherentlyPass); }
private void SetCustomBoardSize() { var thisSize = new GameBoardSize(_customWidth, _customHeight); if (!BoardSizes.Contains(thisSize)) { BoardSizes.Add(thisSize); } SelectedGameBoardSize = thisSize; }
/// <summary> /// Calculates the default compensation (komi). /// </summary> /// <param name="gbSize">Game board size</param> /// <param name="handicapStoneCount">Handicap stone count</param> /// <returns></returns> public static float GetJapaneseCompensation(GameBoardSize gbSize, int handicapStoneCount) { float compensation = 0.0f; if (handicapStoneCount == 0) { compensation = 6.5f; } else { compensation = 0.5f; } return(compensation); }
/// <summary> /// Calculates the default compensation (komi). /// </summary> /// <param name="gbSize">Game board size</param> /// <param name="handicapStoneCount">Handicap stone count</param> /// <returns></returns> public static float GetChineseCompensation(GameBoardSize gbSize, int handicapStoneCount) { float compensation = 0; if (handicapStoneCount == 0) { compensation = 7.5f; } else { compensation = 0.5f + handicapStoneCount - 1; } return(compensation); }
/// <summary> /// Calculates the default compensation (komi). /// </summary> /// <param name="rsType">Type of the ruleset</param> /// <param name="gbSize">Game board size</param> /// <param name="handicapStoneCount">Handicap stone count</param> /// <param name="cType">Counting type</param> /// <returns></returns> public static float GetDefaultCompensation(RulesetType rsType, GameBoardSize gbSize, int handicapStoneCount, CountingType cType) { if (rsType == RulesetType.AGA) { return(AGARuleset.GetAGACompensation(gbSize, handicapStoneCount, cType)); } if (rsType == RulesetType.Chinese) { return(ChineseRuleset.GetChineseCompensation(gbSize, handicapStoneCount)); } if (rsType == RulesetType.Japanese) { return(JapaneseRuleset.GetJapaneseCompensation(gbSize, handicapStoneCount)); } return(0); }
/// <summary> /// Calculates the default compensation (komi). /// </summary> /// <param name="gbSize">Game board size</param> /// <param name="handicapStoneCount">Handicap stone count</param> /// <param name="cType">Counting type</param> /// <returns>Komi compensation.</returns> public static float GetAGACompensation(GameBoardSize gbSize, int handicapStoneCount, CountingType cType) { float compensation = 0; if (handicapStoneCount == 0) { compensation = 7.5f; } else if (handicapStoneCount > 0 && cType == CountingType.Area) { compensation = 0.5f + handicapStoneCount - 1; } else if (handicapStoneCount > 0 && cType == CountingType.Territory) { compensation = 0.5f; } return(compensation); }
/// <summary> /// Returns the positions of handicap stones /// </summary> /// <param name="size">Size of the game board</param> /// <param name="handicap">Handicap stone count</param> /// <returns>Positions of handicap stones</returns> public static IEnumerable <Position> GetHandicapStonePositions(GameBoardSize size, int handicap) { if (!size.IsSquare) { throw new ArgumentOutOfRangeException(nameof(size), "Invalid game board size for fixed handicap"); } Position[] sourceArray = null; switch (size.Width) { case 9: { sourceArray = FixedHandicapPositions9; break; } case 13: { sourceArray = FixedHandicapPositions13; break; } case 19: { sourceArray = FixedHandicapPositions19; break; } default: throw new ArgumentOutOfRangeException(nameof(size), "Invalid game board size for fixed handicap"); } if (handicap > sourceArray.Length) { throw new ArgumentOutOfRangeException(nameof(handicap), "Too many handicap stones requested"); } if (handicap == 6 || handicap == 8) { sourceArray = sourceArray.Take(4).Concat(sourceArray.Skip(5)).ToArray(); } return(sourceArray.Take(handicap)); }
//Methods private int GetBoardHeight(GameBoardSize gameBoardSize) { int value = 0; switch (gameBoardSize) { case GameBoardSize.small: value = 18; return value; case GameBoardSize.medium: value = 21; return value; case GameBoardSize.large: value = 25; return value; default: value = 18; return value; } }
public static char[,] OurBoardToJokerBoard(GameBoard board, GameBoardSize size) { char[,] jokerBoard = new char[size.Width, size.Height]; for (int x = 0; x < size.Width; x++) { for (int y = 0; y < size.Height; y++) { char targetChar = '*'; if (board[x, y] == StoneColor.Black) { targetChar = 'B'; } if (board[x, y] == StoneColor.White) { targetChar = 'W'; } jokerBoard[x, y] = targetChar; } } return(jokerBoard); }
/// <summary> /// Returns the maximum fixed handicap for a given board size /// </summary> /// <param name="size">Game board size</param> /// <returns>Maximum fixed handicap value</returns> public static int GetMaximumHandicap(GameBoardSize size) { if (!size.IsSquare) { throw new ArgumentOutOfRangeException(nameof(size), "Invalid game board size for fixed handicap"); } switch (size.Width) { case 9: return(FixedHandicapPositions9.Length); case 13: return(FixedHandicapPositions13.Length); case 19: return(FixedHandicapPositions19.Length); default: throw new ArgumentOutOfRangeException(nameof(size), "Invalid game board size for fixed handicap"); } }
public int GetBoardWidth(GameBoardSize gameBoardSize) { int value = 0; switch (gameBoardSize) { case GameBoardSize.small: value = 30; return value; case GameBoardSize.medium: value = 40; return value; case GameBoardSize.large: value = 50; return value; default: value = 30; return value; } }
/// <summary> /// Factory method that creates a ruleset of given type and gameboard size /// </summary> /// <param name="ruleset">Ruleset</param> /// <param name="gameBoardSize">Gameboard size</param> /// <param name="countingType">Counting type (AGA)</param> /// <returns>Ruleset</returns> public static IRuleset Create(RulesetType ruleset, GameBoardSize gameBoardSize, CountingType countingType = CountingType.Area) { switch (ruleset) { case RulesetType.Chinese: { return(new ChineseRuleset(gameBoardSize)); } case RulesetType.Japanese: { return(new JapaneseRuleset(gameBoardSize)); } case RulesetType.AGA: { return(new AGARuleset(gameBoardSize, countingType)); } default: throw new ArgumentOutOfRangeException(nameof(ruleset)); } }
public IgsGameInfo( PlayerInfo whitePlayerInfo, PlayerInfo blackPlayerInfo, GameBoardSize boardSize, RulesetType rulesetType, int numberOfHandicapStones, HandicapPlacementType handicapPlacementType, float komi, CountingType countingType, int igsIndex, int numberOfObservers) : base( whitePlayerInfo, blackPlayerInfo, boardSize, rulesetType, numberOfHandicapStones, handicapPlacementType, komi, countingType) { NumberOfObservers = numberOfObservers; IgsIndex = igsIndex; }
protected RemoteGameInfo(PlayerInfo whitePlayerInfo, PlayerInfo blackPlayerInfo, GameBoardSize boardSize, RulesetType rulesetType, int numberOfHandicapStones, HandicapPlacementType handicapPlacementType, float komi, CountingType countingType) : base(whitePlayerInfo, blackPlayerInfo, boardSize, rulesetType, numberOfHandicapStones, handicapPlacementType, komi, countingType) { }
/// <summary> /// Converts a SGF tree branch to GameTreeNode /// </summary> /// <param name="branch">Branch</param> /// <returns>Game tree node</returns> private GameTreeNode ConvertBranch(SgfGameTree branch, GameBoardSize boardSize) { GameTreeNode root = null; GameTreeNode current = null; foreach (var node in branch.Sequence) { GameTreeNode newNode = null; if (node["W"] != null) { SgfPoint point = node["W"].Value <SgfPoint>(); //add white move newNode = new GameTreeNode(Move.PlaceStone(StoneColor.White, Position.FromSgfPoint(point, boardSize))); } else if (node["B"] != null) { SgfPoint point = node["B"].Value <SgfPoint>(); //add black move newNode = new GameTreeNode(Move.PlaceStone(StoneColor.Black, Position.FromSgfPoint(point, boardSize))); } else { //add non-move newNode = new GameTreeNode(Move.NoneMove); } if (node["AW"] != null) { //add white moves var property = node["AW"]; var pointRectangles = property.SimpleValues <SgfPointRectangle>(); newNode.AddWhite.AddRange(GetPositionsFromPointRectangles(pointRectangles, boardSize)); } if (node["AB"] != null) { var property = node["AB"]; var pointRectangles = property.SimpleValues <SgfPointRectangle>(); newNode.AddBlack.AddRange(GetPositionsFromPointRectangles(pointRectangles, boardSize)); } if (node["C"] != null) { var property = node["C"]; var comment = property.Value <string>(); newNode.Comment = comment; } // Fill in all markup properties ParseAndFillMarkupProperties(node, newNode, boardSize); if (current == null) { root = newNode; } else { current.Branches.AddNode(newNode); } current = newNode; } //create root if none were found if (root == null) { root = new GameTreeNode(Move.NoneMove); current = root; } //add branches foreach (var child in branch.Children) { var rootOfBranch = ConvertBranch(child, boardSize); current.Branches.AddNode(rootOfBranch); } return(root); }
/// <summary> /// Initializes the ruleset. For each game, a new ruleset must be created. /// </summary> /// <param name="gbSize">Size of the game board.</param> public ChineseRuleset(GameBoardSize gbSize) : base(gbSize) { }
/// <summary> /// Initializes the ruleset. For each game, a new ruleset must be created. /// </summary> /// <param name="gbSize">Size of the game board.</param> public JapaneseRuleset(GameBoardSize gbSize) : base(gbSize) { }
public StonePlacementTool(GameBoardSize boardSize) { _moveResults = new MoveResult[boardSize.Width, boardSize.Height]; }
/// <summary> /// Yes, the methods do the same thing. /// </summary> private static int InvertY(int y, GameBoardSize boardSize) { return(boardSize.Height - y - 1); }
/// <summary> /// Gets all positions from point rectangles /// </summary> /// <param name="pointRectangles">Point rectangles</param> /// <param name="boardSize">Board size</param> /// <returns>Positions</returns> private IEnumerable <Position> GetPositionsFromPointRectangles(IEnumerable <SgfPointRectangle> pointRectangles, GameBoardSize boardSize) { foreach (var pointRectangle in pointRectangles) { foreach (var point in pointRectangle) { yield return(Position.FromSgfPoint(point, boardSize)); } } }
/// <summary> /// Initializes the ruleset. For each game, a new ruleset must be created. /// </summary> /// <param name="gbSize">Size of the game board.</param> /// <param name="countingType">Chosen couting type.</param> public AGARuleset(GameBoardSize gbSize, CountingType countingType) : base(gbSize) { _countingType = countingType; }
public BoardControlState(GameBoardSize boardSize) : this() { _boardWidth = boardSize.Width; _boardHeight = boardSize.Height; }
/// <summary> /// Initializes the state of ruleset. /// </summary> /// <param name="gbSize">Size of game board.</param> internal RulesetInfo(GameBoardSize gbSize) { BoardSize = gbSize; BoardState = new GameBoard(gbSize); GroupState = new GroupState(this); }
/// <summary> /// Converts a KGS Y coordinate to an OmegaGo Y coordinate. /// </summary> /// <returns></returns> public static int TheirsToOurs(int y, GameBoardSize boardSize) { return(InvertY(y, boardSize)); }
/// <summary> /// Parses and fills markup properties /// </summary> /// <param name="sourceNode">Source SGF node</param> /// <param name="targetNode">Target game tree node</param> /// <param name="boardSize">Board size</param> private void ParseAndFillMarkupProperties(SgfNode sourceNode, GameTreeNode targetNode, GameBoardSize boardSize) { // Needs to handle: string arrow = "AR"; // AR - Arrow string circle = "CR"; // CR - Circle string dimPoint = "DD"; // DD - Dim Point string label = "LB"; // LB - Label string line = "LN"; // LN - Line string cross = "MA"; // MA - Mark With X string selected = "SL"; // SL - Selected string square = "SQ"; // SQ - Square string triangle = "TR"; // TR - Triangle if (sourceNode[arrow] != null) { // Add arrow var property = sourceNode[arrow]; var arrowDefinitions = property.ComposeValues <SgfPoint, SgfPoint>(); foreach (var arrowDefinition in arrowDefinitions) { var fromPoint = Position.FromSgfPoint(arrowDefinition.Left, boardSize); var toPoint = Position.FromSgfPoint(arrowDefinition.Right, boardSize); targetNode.Markups.AddMarkup(new Arrow(fromPoint, toPoint)); } } if (sourceNode[circle] != null) { // Add circle var property = sourceNode[circle]; var pointRectangles = property.SimpleValues <SgfPointRectangle>(); var positions = GetPositionsFromPointRectangles(pointRectangles, boardSize); foreach (var position in positions) { targetNode.Markups.AddMarkup( new Circle(position)); } } if (sourceNode[dimPoint] != null) { // Add dim point var property = sourceNode[dimPoint]; var pointRectangles = property.SimpleValues <SgfPointRectangle>(); foreach (var rectangle in pointRectangles) { var topLeft = Position.FromSgfPoint(rectangle.UpperLeft, boardSize); var bottomRight = Position.FromSgfPoint(rectangle.LowerRight, boardSize); targetNode.Markups.AddMarkup(new AreaDim(topLeft, bottomRight)); } } if (sourceNode[label] != null) { // Add label var property = sourceNode[label]; var labelDefinitions = property.ComposeValues <SgfPoint, string>(); foreach (var labelDefinition in labelDefinitions) { targetNode.Markups.AddMarkup(new Label(Position.FromSgfPoint(labelDefinition.Left, boardSize), labelDefinition.Right)); } } if (sourceNode[line] != null) { // Add line var property = sourceNode[line]; var lineDefinitions = property.ComposeValues <SgfPoint, SgfPoint>(); foreach (var lineDefinition in lineDefinitions) { var startPoint = Position.FromSgfPoint(lineDefinition.Left, boardSize); var endPoint = Position.FromSgfPoint(lineDefinition.Right, boardSize); targetNode.Markups.AddMarkup(new Line(startPoint, endPoint)); } } if (sourceNode[cross] != null) { // Add cross var property = sourceNode[cross]; var pointRectangles = property.SimpleValues <SgfPointRectangle>(); var positions = GetPositionsFromPointRectangles(pointRectangles, boardSize); foreach (var position in positions) { targetNode.Markups.AddMarkup( new Cross(position)); } } if (sourceNode[selected] != null) { // Add selected // TODO (future work) Vita : implement } if (sourceNode[square] != null) { // Add square var property = sourceNode[square]; var pointRectangles = property.SimpleValues <SgfPointRectangle>(); var positions = GetPositionsFromPointRectangles(pointRectangles, boardSize); foreach (var position in positions) { targetNode.Markups.AddMarkup( new Square(position)); } } if (sourceNode[triangle] != null) { // Add triangle var property = sourceNode[triangle]; var pointRectangles = property.SimpleValues <SgfPointRectangle>(); var positions = GetPositionsFromPointRectangles(pointRectangles, boardSize); foreach (var position in positions) { targetNode.Markups.AddMarkup( new Triangle(position)); } } }
/// <summary> /// Initializes BoardViewModel with given board size. /// </summary> /// <param name="boardSize">Board size</param> public BoardViewModel(GameBoardSize boardSize) : this() { BoardControlState = new BoardControlState(boardSize); }
public KgsGameInfo(PlayerInfo whitePlayerInfo, PlayerInfo blackPlayerInfo, GameBoardSize boardSize, RulesetType rulesetType, int numberOfHandicapStones, HandicapPlacementType handicapPlacementType, float komi, CountingType countingType, int channelId) : base(whitePlayerInfo, blackPlayerInfo, boardSize, rulesetType, numberOfHandicapStones, handicapPlacementType, komi, countingType) { this.ChannelId = channelId; }
public GameOptions(GameBoardSize boardSize, GameDifficulty difficulty) { BoardSize = boardSize; Difficulty = difficulty; }
/// <summary> /// Initializes the ruleset. For each game, a new ruleset must be created. /// </summary> /// <param name="gbSize">Size of the game board.</param> protected Ruleset(GameBoardSize gbSize) { RulesetInfo = new RulesetInfo(gbSize); GameBoard newBoard = new GameBoard(gbSize); GroupState groupState = new GroupState(RulesetInfo); }