コード例 #1
0
        private void LoadProblem(TsumegoProblem problem)
        {
            Rectangle rect = problem.GetBoundingBoard();

            BoardViewModel.BoardControlState.OriginX     = rect.X;
            BoardViewModel.BoardControlState.OriginY     = rect.Y;
            BoardViewModel.BoardControlState.BoardWidth  = rect.Width;
            BoardViewModel.BoardControlState.BoardHeight = rect.Height;
            _currentProblem            = problem;
            _currentProblemTree        = _currentProblem.SpawnThisProblem();
            CurrentProblemName         = _currentProblem.Name;
            CurrentProblemInstructions = _currentProblemTree.Comment;
            CurrentNode   = _currentProblemTree;
            _playerToMove = _currentProblem.ColorToPlay;
            _humansColor  = _playerToMove;
            if (_humansColor == StoneColor.Black)
            {
                CurrentNodeStatus = Localizer.Tsumego_BlackToPlay;
            }
            else
            {
                CurrentNodeStatus = Localizer.Tsumego_WhiteToPlay;
            }
            WrongVisible   = false;
            CorrectVisible = false;
            GoToPreviousProblemCommand.RaiseCanExecuteChanged();
            GoToNextProblemCommand.RaiseCanExecuteChanged();
            UndoOneMoveCommand.RaiseCanExecuteChanged();
            RaisePropertyChanged(nameof(CurrentProblemPermanentlySolved));
        }
コード例 #2
0
    /// <summary>
    /// 任意のマスから指定された方向に対し、相手の石を挟める場所に自分の石が配置されているかチェックします
    /// </summary>

    bool Turncheck(Game_Cell cell, StoneColor stoneColor, int xDirection, int yDirection)
    {
        int  x = cell.X;
        int  y = cell.Y;
        bool existEnemyStone = false;

        while (true)
        {
            x = x + xDirection;
            y = y + yDirection;
            Game_Cell targetCell = GetCell(x, y);
            if (targetCell == null || targetCell.GetStoneColor() == StoneColor.None)
            {
                return(false);
            }
            else if (targetCell.GetStoneColor() == stoneColor)
            {
                return(existEnemyStone);
            }
            else
            {
                existEnemyStone = true;
            }
        }
    }
コード例 #3
0
ファイル: Goboard.cs プロジェクト: rocbomb/homework-07
		public GoBoard(int nSize)
		{
			InitializeComponent();

			this.nSize = nSize;  //当前棋盘大小

			m_colorToPlay = StoneColor.black;

			Grid = new Spot[nSize,nSize];
			for (int i=0; i<nSize; i++)
				for (int j=0; j<nSize; j++)
					Grid[i,j] = new Spot();
			penGrid = new Pen(Color.Brown, (float)0.5);
			penStoneW = new Pen(Color.WhiteSmoke, (float)1);
			penStoneB = new Pen(Color.Black,(float)1);
			penMarkW = new Pen(Color.Blue, (float) 1);
			penMarkB = new Pen(Color.Beige, (float) 1);

			brStar = new SolidBrush(Color.Black);
			brBoard = new SolidBrush(Color.Orange);
			brBlack = new SolidBrush(Color.Black);
			brWhite = new SolidBrush(Color.White);
			m_brMark = new SolidBrush(Color.Red);

			rGrid = new Rectangle(nEdgeLen, nEdgeLen,nTotalGridWidth, nTotalGridWidth);
			strLabels = new string [] {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t"};
			gameTree = new GoTree();
		}
コード例 #4
0
 internal Option()
 {
     _Difficulty = Difficulty.Medium;
     _Player = StoneColor.White;
     _StartColor = StoneColor.Black;
     Changed = true;
 }
コード例 #5
0
ファイル: Board.cs プロジェクト: IdoPudi/CodeValueExercises
 public bool CanPutGameStoneBackInBoard(StoneColor Color, int CellNumber)
 {
     if (Color == StoneColor.White)
     {
         if (_barWhite == 0)
         {
             return(false);
         }
         if (_boardCells[CellNumber].Color == StoneColor.Black && _boardCells[CellNumber].Number > 1)
         {
             return(false);
         }
         return(true);
     }
     else
     {
         if (_barBlack == 0)
         {
             return(false);
         }
         if (_boardCells[CellNumber].Color == StoneColor.White && _boardCells[CellNumber].Number > 1)
         {
             return(false);
         }
         return(true);
     }
 }
コード例 #6
0
        /// <summary>
        /// Adds stone to the group map, group list and board.
        /// </summary>
        /// <param name="position">Position on the board.</param>
        /// <param name="color">Color of stone.</param>
        internal void AddStoneToBoard(Position position, StoneColor color)
        {
            Group      newGroup        = CreateNewGroup(color, position);
            List <int> neighbourGroups = GetNeighbourGroups(position);

            foreach (int groupID in neighbourGroups)
            {
                Group group = Groups[groupID];
                group.DecreaseLibertyCount(1);
                //join
                if (group.GroupColor == newGroup.GroupColor)
                {
                    //choose group with smaller ID
                    if (group.ID < newGroup.ID)
                    {
                        newGroup.JoinGroupWith(group);
                        newGroup = group;
                    }
                    else
                    {
                        group.JoinGroupWith(newGroup);
                    }
                }
            }

            _rulesetInfo.BoardState[position.X, position.Y] = color;
        }
コード例 #7
0
 public AIPlayer2(StoneColor color)
 {
     this.Color = color;
     this.Name  = "ziro";
     this.rule  = new Rule();
     CreateEvaluation();
 }
コード例 #8
0
ファイル: AIPlayer2.cs プロジェクト: kkawaguchi/osero
 public AIPlayer2(StoneColor color)
 {
     this.Color = color;
     this.Name = "ziro";
     this.rule = new Rule();
     CreateEvaluation();
 }
コード例 #9
0
        public void RenderStone(Vector2f center, float diameter, StoneColor color)
        {
            float radius = diameter / 2;

            switch (color)
            {
            case StoneColor.None:
            {
                break;
            }

            case StoneColor.Black:
            {
                Graphics.FillCircle(RawColor.Black, center, radius);
                break;
            }

            case StoneColor.White:
            {
                Graphics.FillCircle(RawColor.White, center, radius);
                Graphics.DrawCircle(new Pen(RawColor.Black, 1), center, radius);
                break;
            }

            default:
                throw new NotImplementedException();
            }
        }
コード例 #10
0
    /// <summary>
    /// 任意のマスから指定された方向に対し、相手の石を挟める場所に自分の石が配置されているかチェックします
    /// </summary>
    /// <returns><c>true</c>, if own stone at the other side of enemy stone for direction was existsed, <c>false</c> otherwise.</returns>
    /// <param name="cell">Cell.</param>
    /// <param name="xDirection">X direction.</param>
    /// <param name="yDirection">Y direction.</param>
    bool ExistsOwnStoneAtTheOtherSideOfEnemyStoneForDirection(Game_Cell cell, StoneColor stoneColor, int xDirection, int yDirection)
    {
        var x = cell.X;
        var y = cell.Y;

        var existsEnemyStone = false;

        while (true)
        {
            x += xDirection;
            y += yDirection;
            var targetCell = GetCell(x, y);
            if (null == targetCell || targetCell.StoneColor == StoneColor.None)
            {
                return(false);
            }
            else if (targetCell.StoneColor == stoneColor)
            {
                return(existsEnemyStone);
            }
            else
            {
                existsEnemyStone = true;
            }
        }
    }
コード例 #11
0
ファイル: StoneRemover.cs プロジェクト: ipartington/GoGame-1
    private void RemoveByChainOnRightSurroundedStrategy(int x, int y, StoneColor oppositeColor)
    {
        RemovableDetector detector = new ChainRemovableDetector();
        List<Tuple<int, int>> results = detector.Detect(_args);

        RemoveAllItemsInList(results);
    }
コード例 #12
0
        public void Execute(IToolServices toolService)
        {
            StoneColor previousPlayer = toolService.Node.Move.WhoMoves;
            StoneColor nextPlayer     = StoneColor.None;

            //set next player
            if (previousPlayer == StoneColor.White)
            {
                nextPlayer = StoneColor.Black;
            }
            else if (previousPlayer == StoneColor.Black)
            {
                nextPlayer = StoneColor.White;
            }
            else
            {
                if (toolService.Node.Equals(toolService.GameTree.GameTreeRoot))
                {
                    nextPlayer = StoneColor.Black;
                }
                else
                {
                    nextPlayer = StoneColor.White;
                }
            }

            GameTreeNode newNode = new GameTreeNode(Move.Pass(nextPlayer));

            newNode.BoardState = new GameBoard(toolService.Node.BoardState);
            newNode.GroupState = new GroupState(toolService.Node.GroupState, toolService.Ruleset.RulesetInfo);
            toolService.Node.Branches.AddNode(newNode);

            toolService.SetNode(newNode);
            toolService.PlayPassSound();
        }
コード例 #13
0
 /// <summary>
 /// 各マスのクリック可否状態を更新します
 /// </summary>
 public void UpdateCellsClickable(StoneColor stoneColor)
 {
     foreach (Game_Cell cell in cells)
     {
         cell.SetClickable(IsStonePuttableCell(cell, stoneColor));
     }
 }
コード例 #14
0
        /// <summary>
        /// Gets or sets score for a given stone color.
        /// </summary>
        /// <param name="color">Stone color</param>
        /// <returns>Score</returns>
        public float this[StoneColor color]
        {
            get
            {
                switch (color)
                {
                case StoneColor.Black:
                    return(BlackScore);

                case StoneColor.White:
                    return(WhiteScore);

                default:
                    throw new ArgumentOutOfRangeException(nameof(color), color, null);
                }
            }
            set
            {
                switch (color)
                {
                case StoneColor.Black:
                    BlackScore = value;
                    break;

                case StoneColor.White:
                    WhiteScore = value;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(color), color, null);
                }
            }
        }
コード例 #15
0
 /// <summary>
 /// Internal player setter
 /// </summary>
 /// <param name="player">Player</param>
 /// <param name="color">Color of the player</param>
 private void SetPlayerCore(GamePlayer player, StoneColor color)
 {
     if (color == StoneColor.None)
     {
         throw new ArgumentOutOfRangeException(nameof(color), "Color must be valid for a player");
     }
     if (player == null)
     {
         throw new ArgumentNullException(nameof(player));
     }
     if (player.Info.Color != color)
     {
         throw new ArgumentException("The provided player color doesn't match expectation.", nameof(player));
     }
     if (!ValidatePlayer(player))
     {
         throw new ArgumentException("The provided player is not valid for this type of game", nameof(player));
     }
     if (color == StoneColor.White)
     {
         _whitePlayer = player;
     }
     if (color == StoneColor.Black)
     {
         _blackPlayer = player;
     }
 }
コード例 #16
0
        public IShadowItem GetShadowItem(IToolServices toolService)
        {
            if (toolService.Node.Equals(toolService.GameTree.GameTreeRoot))
            {
                int width  = toolService.GameTree.BoardSize.Width;
                int height = toolService.GameTree.BoardSize.Height;
                MoveResult[,] moveResults = new MoveResult[width, height];
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        moveResults[x, y] = MoveResult.Legal;
                    }
                }
                _currentNode = toolService.Node;
            }
            else if (!toolService.Node.Equals(_currentNode) || _currentNode == null)
            {
                _moveResults = toolService.Ruleset.GetMoveResult(toolService.Node);
                _currentNode = toolService.Node;
            }

            MoveResult result     = _moveResults[toolService.PointerOverPosition.X, toolService.PointerOverPosition.Y];
            StoneColor nextPlayer = toolService.Node.Move.WhoMoves.GetOpponentColor(toolService.Node, toolService.GameTree.GameTreeRoot);

            if (result == MoveResult.Legal)
            {
                return(new Stone(nextPlayer, toolService.PointerOverPosition));
            }
            else
            {
                return(new None());
            }
        }
コード例 #17
0
 public void Raise(Vector2 p, StoneColor c)
 {
     for (int i = eventListeners.Count - 1; i >= 0; i--)
     {
         eventListeners[i].OnEventRaised(p, c);
     }
 }
コード例 #18
0
        private bool GetSquareMarker(RawColor[] squares, double blockSize, StoneColor stoneColor)
        {
            int blackSquare = 0;
            int whiteSquare = 0;

            for (int r = (int)blockSize / 4; r < (int)blockSize / 2; r++)
            {
                if (squares[r] != RawColor.Transparent && IsGray(squares[r]))
                {
                    if (squares[r].GetUnweightedBrightness() < 0.2)
                    {
                        blackSquare++;
                    }
                    if (squares[r].GetUnweightedBrightness() > 0.8)
                    {
                        whiteSquare++;
                    }
                }
            }
            switch (stoneColor)
            {
            case StoneColor.None:
            case StoneColor.White:
                return(blackSquare > 0);

            case StoneColor.Black:
                return(whiteSquare > 0);

            default:
                throw new NotImplementedException();
            }
        }
コード例 #19
0
        /// <summary>
        /// Creates a tsumego problem from the contents of an SGF file downloaded from online-go.com using
        /// the Ruby downloader.
        /// </summary>
        /// <param name="data">The contents of an SGF file.</param>
        /// <returns></returns>
        public static TsumegoProblem CreateFromSgfText(string data)
        {
            SgfParser   parser       = new SgfParser();
            var         collection   = parser.Parse(data);
            SgfGameTree sgfTree      = collection.GameTrees.First();
            string      problemName  = "";
            StoneColor  playerToPlay = StoneColor.None;

            foreach (var node in sgfTree.Sequence)
            {
                if (node["GN"] != null)
                {
                    problemName = node["GN"].Value <string>();
                }
                if (node["PL"] != null)
                {
                    SgfColor sgfColor = node["PL"].Value <SgfColor>();
                    switch (sgfColor)
                    {
                    case SgfColor.Black:
                        playerToPlay = StoneColor.Black;
                        break;

                    case SgfColor.White:
                        playerToPlay = StoneColor.White;
                        break;
                    }
                }
            }
            return(new TsumegoProblem(problemName, sgfTree, playerToPlay));
        }
コード例 #20
0
        private bool GetCircleMarker(RawColor[] circles, double blockSize, StoneColor stoneColor)
        {
            int blackRing = 0;
            int whiteRing = 0;

            for (int r = 3; r < (int)blockSize / 3; r++)
            {
                if (circles[r] != RawColor.Transparent && IsGray(circles[r]))
                {
                    if (circles[r].GetUnweightedBrightness() < 0.35)
                    {
                        blackRing++;
                    }
                    if (circles[r].GetUnweightedBrightness() > 0.65)
                    {
                        whiteRing++;
                    }
                }
            }
            switch (stoneColor)
            {
            case StoneColor.None:
            case StoneColor.White:
                return(blackRing > 0);

            case StoneColor.Black:
                return(whiteRing > 0);

            default:
                throw new NotImplementedException();
            }
        }
コード例 #21
0
        /// <summary>
        /// Receives and handles resignation from server
        /// </summary>
        /// <param name="resigningPlayerColor">Color of the resigning player</param>
        public void ResignationFromServer(StoneColor resigningPlayerColor)
        {
            var player   = _gameController.Players[resigningPlayerColor];
            var igsAgent = player.Agent as IgsAgent;

            igsAgent?.ResignationFromServer();
        }
コード例 #22
0
 protected TsumegoProblem(string name, SgfGameTree tree, StoneColor colorToPlay)
 {
     this.Name        = name;
     this.SgfGameTree = tree;
     this.ColorToPlay = colorToPlay;
     this.InitialTree = SpawnThisProblem();
 }
コード例 #23
0
    /// <summary>
    /// 任意のマスから指定された方向に対し、相手の石を挟める場所に自分の石が配置されているかチェックします
    /// </summary>

    bool Turncheck(Game_Cell cell, StoneColor stoneColor, int xDirection, int yDirection)
    {
        int x = cell.X;
        int y = cell.Y;
        //相手の石を挟めるかどうか
        bool existEnemyStone = false;

        while (true)
        {
            //各座標をそれぞれのDirectionずつずらす
            x = x + xDirection;
            y = y + yDirection;
            //(x,y)座標のcellを取得
            Game_Cell targetCell = GetCell(x, y);
            //targetCellがnullまたは、色が無い場合、false
            if (targetCell == null || targetCell.GetStoneColor() == StoneColor.None)
            {
                return(false);
            }
            //targetCellと任意のマスの色が同じだった場合、その時点でのexistEnemyStoneを返す
            else if (targetCell.GetStoneColor() == stoneColor)
            {
                return(existEnemyStone);
            }
            //targetCellと任意のマスの色が違う場合、existEnemyStoneをtrueに
            else
            {
                existEnemyStone = true;
            }
        }
    }
コード例 #24
0
        public bool TryPutStone(string cellId, StoneColor color)
        {
            if (!TryGetTargetIndexKeys(cellId, out (char columnIndex, int rawIndex)result))
            {
                return(false);
            }
            var targetIndices = (raw : _rawIndexMap[result.rawIndex], column : _columnIndexMap[result.columnIndex]);

            if (!_stones[targetIndices.raw, targetIndices.column].IsEmpty)
            {
                _logMessages.Add("そこにはもう石が置いてある!");
                return(false);
            }

            var stone = new Stone((targetIndices.raw, targetIndices.column), color);

            //OnPutStone?.Invoke(this, stone);
            if (!TryReverseAllAdjacent(stone))
            {
                _logMessages.Add("そこに置いても何もひっくり返せない!");
                return(false);
            }

            _stones[targetIndices.raw, targetIndices.column] = stone;
            if (color == StoneColor.Black)
            {
                _blackCount++;
            }
            else if (color == StoneColor.White)
            {
                _whiteCount++;
            }
            return(true);
        }
コード例 #25
0
ファイル: Board.xaml.cs プロジェクト: ycw805730732/x01.Weiqi
        //   +
        // + + +	与 step 相连的棋子,包含自身
        //   +		根据 color 参数决定是所有,同色,黑色,白色,还是空色。
        List <Step> LinkSteps(Step step, StoneColor color = StoneColor.Empty)
        {
            List <Step> links = new List <Step>();

            for (int i = -1; i < 2; i++)
            {
                for (int j = -1; j < 2; j++)
                {
                    if (i == j || i == -j)
                    {
                        continue;
                    }
                    if (Helper.InRange(step.Row + i, step.Col + j))
                    {
                        links.Add(m_Steps[step.Row + i, step.Col + j]);
                    }
                }
            }
            links.Add(step);
            if (color == StoneColor.All)
            {
                return(links);
            }
            else
            {
                links.RemoveAll(l => l.StoneColor != color);
                return(links);
            }
        }
コード例 #26
0
        /// <summary>
        /// 盤上の全交点に、その場所の石(または連)の総呼吸点の数を埋めます。
        ///
        /// Gnugo1.2 では、eval 関数。
        /// </summary>
        /// <param name="libertyOfNodes">
        /// Gnugo1.2 では、l という名前のグローバル変数。liberty の略だろうか?
        /// eval で内容が設定され、その内容は exambord、findsavr、findwinr、suicideで使用されます。
        /// </param>
        /// <param name="color">黒 or 白</param>
        public static void CountAll
        (
            out int[,] libertyOfNodes,
            StoneColor color,
            Taikyoku taikyoku
        )
        {
            int banSize = taikyoku.GobanBounds.BoardSize; // 何路盤

            libertyOfNodes = new int[taikyoku.GobanBounds.BoardSize, taikyoku.GobanBounds.BoardSize];

            // それぞれのピースの総呼吸点の数を数えます。
            for (int i = 0; i < banSize; i++)
            {
                for (int j = 0; j < banSize; j++)
                {
                    GobanPoint iLocation = new GobanPointImpl(i, j);
                    if (taikyoku.Goban.At(iLocation) == color) // 指定の色の石のみ
                    {
                        int liberty;                           // Gnugo1.2 では、グローバル変数 lib = 0 でした。
                        Util_CountLiberty.Count(out liberty, iLocation, color, taikyoku);
                        libertyOfNodes[i, j] = liberty;
                    }
                }
            }
        }
コード例 #27
0
 public static Move Pass(StoneColor whoMoves)
 {
     return(new Move()
     {
         WhoMoves = whoMoves,
         Kind = MoveKind.Pass
     });
 }
コード例 #28
0
 public override GamePlayer Build(StoneColor color, TimeControlSettingsViewModel timeSettings, PlayerSettingsViewModel settings)
 {
     return(new HumanPlayerBuilder(color)
            .Name(color == StoneColor.Black ? _localizer.Black : _localizer.White)
            .Rank("NR")
            .Clock(timeSettings.Build())
            .Build());
 }
コード例 #29
0
ファイル: ForBoard.cs プロジェクト: ycw805730732/x01.Weiqi
 public Pos(int row, int col, StoneColor color = Boards.StoneColor.Empty, int stepCount = -1, int worth = -1)
 {
     Row        = row;
     Col        = col;
     StepCount  = stepCount;
     Worth      = worth;
     StoneColor = color;
 }
コード例 #30
0
 public void StoreMove(int oneIndexMoveNumber, StoneColor color, Move move)
 {
     if (this.Color == color)
     {
         _storedMoves[oneIndexMoveNumber - 1] = move;
         MaybeMakeAMove();
     }
 }
コード例 #31
0
        /// <summary>
        /// Creates new group intance with one member.
        /// </summary>
        /// <param name="color">Color of stones in group.</param>
        /// <param name="position">The position of group member.</param>
        /// <returns>Created group with one member.</returns>
        internal Group CreateNewGroup(StoneColor color, Position position)
        {
            int   ID       = GetUniqueID();
            Group newGroup = new Group(ID, color, _rulesetInfo);

            newGroup.AddStoneToEmptyGroup(position);
            return(newGroup);
        }
コード例 #32
0
ファイル: Print.cs プロジェクト: IdoPudi/CodeValueExercises
 public void PlayerTurn(StoneColor Color)
 {
     Console.Clear();
     Console.WriteLine($"********************");
     Console.WriteLine($"Player {Color} turn");
     Console.WriteLine($"********************");
     Console.WriteLine($"Press any key to start turn");
     Console.ReadKey();
 }
コード例 #33
0
ファイル: Board.cs プロジェクト: ipartington/GoGame-1
        public void AddStone(StoneColor stoneColor, int x, int y)
        {
            rules.NotifyStoneAdded(stoneColor, x, y);

            positionStatusMatrix[x, y] = PositionStatus.FilledPosition;
            stoneColorMatrix[x, y] = stoneColor;

            rules.CheckStonesAroundPositionAndRemoveIfNeeded(x, y);
        }
コード例 #34
0
 /// <summary>
 /// Creates a new structure that gives the AI information it needs to make a move.
 /// </summary>
 /// <param name="gameInfo">Game info</param>
 /// <param name="aiColor">The player whose turn it is. The AI will make a move for this player.</param>
 /// <param name="aiPlayer">AI player</param>
 /// <param name="gameTree">The current full board state (excluding information about Ko). </param>
 public AiGameInformation(GameInfo gameInfo, StoneColor aiColor, GamePlayer aiPlayer, GameTree gameTree)
 {
     GameInfo = gameInfo;
     AIColor  = aiColor;
     AiPlayer = aiPlayer;
     GameTree = gameTree;
     Node     = gameTree.LastNode; // Some concurrency problems may occur here, but they're very unlikely.
     // If we want to solve them, then gameTree.LastNode should be given as an argument to this.
 }
コード例 #35
0
ファイル: Print.cs プロジェクト: IdoPudi/CodeValueExercises
 public void WinningPlayer(StoneColor Color)
 {
     Console.WriteLine($"**********************");
     Console.WriteLine($"We have a winner!!!!!");
     Console.WriteLine($"**********************");
     Console.WriteLine($"Player {Color} Win");
     Console.WriteLine($"**********************");
     Console.ReadKey();
 }
コード例 #36
0
ファイル: Game.cs プロジェクト: kkawaguchi/osero
 public bool PutStone(CellPoint point,StoneColor color)
 {
     if (rule.CanPutStoneToCell(new Stone(color), this.Board.GetCell(point)))
     {
         rule.PutStoneToCell(new Stone(color), this.Board.GetCell(point));
         MoveToNextPalyer();
         return true;
     }
     return false;
 }
コード例 #37
0
        public bool IsFullySurroundedBy(int x, int y, StoneColor surroundingStoneColor)
        {
            bool surroundedOnLeft = (x < Rules.EDGE || _b.GetStoneColor(x - 1, y) == surroundingStoneColor);
            bool surroundedOnRight = (x > Board.BOARDSIZE - Rules.EDGE || _b.GetStoneColor(x + 1, y) == surroundingStoneColor);
            bool surroundedOnBottom = (y > Board.BOARDSIZE - Rules.EDGE || _b.GetStoneColor(x, y + 1) == surroundingStoneColor);
            bool surroundedOnTop = (y < Rules.EDGE || _b.GetStoneColor(x, y - 1) == surroundingStoneColor);

            bool fullySurrounded = surroundedOnLeft && surroundedOnRight && surroundedOnTop && surroundedOnBottom;
            return fullySurrounded;
        }
コード例 #38
0
    public bool IsAlmostFullySurrounded(int x, int y, StoneColor surroundingStoneColor)
    {
        int EDGE = Rules.EDGE;
        Board Board = _args.Board;

        if (Board.GetStoneColor(x, y) == StoneColor.Empty)
        {
            return false;
        }

        bool surroundedOnLeft = (x < EDGE || Board.GetStoneColor(x - 1, y) == surroundingStoneColor);
        bool surroundedOnRight = (x > Board.BOARDSIZE - EDGE || Board.GetStoneColor(x + 1, y) == surroundingStoneColor);
        bool surroundedOnBottom = (y > Board.BOARDSIZE - EDGE || Board.GetStoneColor(x, y + 1) == surroundingStoneColor);
        bool surroundedOnTop = (y < EDGE || Board.GetStoneColor(x, y - 1) == surroundingStoneColor);

        int surroundedEdges = 0;
        if (surroundedOnTop) surroundedEdges++;
        if (surroundedOnRight) surroundedEdges++;
        if (surroundedOnLeft) surroundedEdges++;
        if (surroundedOnBottom) surroundedEdges++;

        bool surroundedOnLeftSameColor = (x < EDGE || Board.GetStoneColor(x - 1, y) == Board.GetStoneColor(x, y));
        bool surroundedOnRightSameColor = (x > Board.BOARDSIZE - EDGE || Board.GetStoneColor(x + 1, y) == Board.GetStoneColor(x, y));
        bool surroundedOnBottomSameColor = (y > Board.BOARDSIZE - EDGE || Board.GetStoneColor(x, y + 1) == Board.GetStoneColor(x, y));
        bool surroundedOnTopSameColor = (y < EDGE || Board.GetStoneColor(x, y - 1) == Board.GetStoneColor(x, y));

        int surroundedEdgesSameColor = 0;
        if (surroundedOnTopSameColor) surroundedEdgesSameColor++;
        if (surroundedOnRightSameColor) surroundedEdgesSameColor++;
        if (surroundedOnLeftSameColor) surroundedEdgesSameColor++;
        if (surroundedOnBottomSameColor) surroundedEdgesSameColor++;

        bool fullySurrounded = surroundedEdges == 3 && surroundedEdgesSameColor == 1;

        return fullySurrounded;
    }
コード例 #39
0
 public void RenderStone(Vector2f center, float diameter, StoneColor color)
 {
     float radius = diameter / 2;
     switch (color)
     {
         case StoneColor.None:
             {
                 break;
             }
         case StoneColor.Black:
             {
                 Graphics.FillCircle(RawColor.Black, center, radius);
                 break;
             }
         case StoneColor.White:
             {
                 Graphics.FillCircle(RawColor.White, center, radius);
                 Graphics.DrawCircle(new Pen(RawColor.Black, 1), center, radius);
                 break;
             }
         default:
             throw new NotImplementedException();
     }
 }
コード例 #40
0
 //ZZZZ ZZ ZZZZZZZZ ZZ ZZZZZZZ ZZZ ZZZ ZZZZ ZZZZ ZZZZ.
 void recordMove(Point p, StoneColor colorToPlay)
 {
     Grid[p.X,p.Y].setStone(colorToPlay);
     // ZZZZZZ ZZZZ ZZZZ.
     m_gmLastMove = new GoMove(p.X, p.Y, colorToPlay, nSeq++);
 }
コード例 #41
0
 StoneColor nextTurn(StoneColor c)
 {
     if (c == StoneColor.Black)
         return StoneColor.White;
     else
         return StoneColor.Black;
 }
コード例 #42
0
        /**
         * ZZZZ Z ZZZZZ (ZZZZZ/ZZZZZ) ZZ ZZZZZZZZ ZZZZZZZZ.
         */
        void drawStone(Graphics g, int row, int col, StoneColor c)
        {
            Brush br;
            if (c == StoneColor.White)
                br = brWhite;
            else
                br = brBlack;

            Rectangle r = new Rectangle(rGrid.X+ (row) * nUnitGridWidth - (nUnitGridWidth-1)/2,
                rGrid.Y + (col) * nUnitGridWidth - (nUnitGridWidth-1)/2,
                nUnitGridWidth-1,
                nUnitGridWidth-1);

            g.FillEllipse(br, r);
        }
コード例 #43
0
 /**
  * ZZZZZZ ZZZ ZZZZ ZZZZZ ZZZ ZZZZZ ZZZZ ZZZZ ZZZ ZZZZZ.
  */
 void doDeadGroup(StoneColor c)
 {
     int i,j;
     for (i=0; i<nSize; i++)
         for (j=0; j<nSize; j++)
             if (Grid[i,j].HasStone() &&
                 Grid[i,j].Color() == c)
             {
                 if (calcLiberty(i,j,c) == 0)
                 {
                     buryTheDead(i,j,c);
                     m_fAnyKill = true;
                 }
                 cleanScanStatus();
             }
 }
コード例 #44
0
ファイル: Rules.cs プロジェクト: ipartington/GoGame-1
 public void NotifyStoneAdded(StoneColor stoneColor, int x, int y)
 {
 }
コード例 #45
0
ファイル: Game.cs プロジェクト: kkawaguchi/osero
 public bool PutStone(int x, int y, StoneColor color)
 {
     return PutStone(new CellPoint(x,y),color);
 }
コード例 #46
0
 public void RenderStone(Vector2i position, StoneColor color, bool faded)
 {
     RenderStone(new Vector2f(position.X, position.Y), color, 0.8f, faded);
 }
コード例 #47
0
ファイル: Game.cs プロジェクト: kkawaguchi/osero
 private StoneColor ChangeColor(StoneColor color)
 {
     return color == StoneColor.Black ? StoneColor.White : StoneColor.Black;
 }
コード例 #48
0
        public void PlayNext(ref GoMove gm)
        {
            Point p = gm.Point;
            m_colorToPlay = gm.Color;	//ZZZ ZZZZZ, ZZZZZZZZZ ZZZZ ZZZZZZ ZZZZ ZZZZ ZZZZ.

            //ZZZZZ ZZZ ZZZZZ/ZZZZZZ ZZ ZZZZZZZ ZZZZZZZZZ
            clearLabelsAndMarksOnBoard();

            if (m_gmLastMove != null)
                repaintOneSpotNow(m_gmLastMove.Point);

            bDrawMark = true;
            Grid[p.X,p.Y].setStone(gm.Color);
            m_gmLastMove = new GoMove(p.X, p.Y, gm.Color, nSeq++);
            //ZZZ ZZZZZ/ZZZZ
            setLabelsOnBoard(gm);
            setMarksOnBoard(gm);

            doDeadGroup(nextTurn(m_colorToPlay));
            //ZZ ZZZ ZZZZZ ZZZ ZZZZ, ZZ ZZZZ ZZ ZZZZZZZZ ZZZZ, ZZ ZZZZ ZZ ZZZ ZZZZZZZ ZZZZ ZZ ZZZZZZZZ.
            if (m_fAnyKill)
                appendDeadGroup(ref gm, nextTurn(m_colorToPlay));
            else //ZZZZ ZZ ZZZ ZZ ZZ'Z Z ZZZZZZZ
            {
                doDeadGroup(m_colorToPlay);
                if (m_fAnyKill)
                    appendDeadGroup(ref gm, m_colorToPlay);
            }
            m_fAnyKill = false;

            optRepaint();

            //ZZZZZZ ZZZZZ
            m_colorToPlay = nextTurn(m_colorToPlay);

            //ZZZZ ZZZ ZZZZZZZ, ZZ ZZZ
            textBox1.Clear();
            textBox1.AppendText(gm.Comment);
        }
コード例 #49
0
ファイル: Goboard.cs プロジェクト: rocbomb/homework-06
        /**
         * ���ĵݹ����
         */
        int calcLiberty(int x, int y, StoneColor c)
        {
            int lib = 0;

            if (!onBoard(x,y))
                return 0;
            if (Grid[x,y].isScanned())
                return 0;

            if (Grid[x,y].hasStone())
            {
                if (Grid[x,y].color() == c)
                {
                    //�ֽ��Լ��������  Ȼ��ݹ顣������
                    Grid[x,y].setScanned();
                    lib += calcLiberty(x-1, y, c);
                    lib += calcLiberty(x+1, y, c);
                    lib += calcLiberty(x, y-1, c);
                    lib += calcLiberty(x, y+1, c);
                }
                else
                    return 0;
            }
            else
            {// �ҵ��� ��Ƿ�ֹ�ظ�����
                lib ++;
                Grid[x,y].setScanned();
            }

            return lib;
        }
コード例 #50
0
ファイル: Goboard.cs プロジェクト: rocbomb/homework-06
 public void setStone(StoneColor c)
 {
     if (bEmpty)
     {
         bEmpty = false;
         s.color = c;
         bUpdated = true;
     } // ���õ�ǰ���̵���ɫΪc,�����ǿ����Ѹ���.
 }
コード例 #51
0
ファイル: Goboard.cs プロジェクト: rocbomb/homework-06
        public void playNext(ref GoMove gm)
        {
            Point p = gm.Point;
            m_colorToPlay = gm.Color;	//��ǰ��ɫΪ��ǰ���ӵ���ɫ

            //������е�label mark
            clearLabelsAndMarksOnBoard();

            if (m_gmLastMove != null)
                repaintOneSpotNow(m_gmLastMove.Point);

            bDrawMark = true;
            Grid[p.X,p.Y].setStone(gm.Color);
            m_gmLastMove = new GoMove(p.X, p.Y, gm.Color, nSeq++);
            //���»���marks labels
            setLabelsOnBoard(gm);
            setMarksOnBoard(gm);

            doDeadGroup(nextTurn(m_colorToPlay));

            //�������������
            if (m_fAnyKill)
                appendDeadGroup(ref gm, nextTurn(m_colorToPlay)); //��¼����
            else //����Լ���û���Բе��Լ��³���������
            {
                doDeadGroup(m_colorToPlay);
                if (m_fAnyKill)
                    appendDeadGroup(ref gm, m_colorToPlay);
            }
            m_fAnyKill = false;

            optRepaint();

            //�Է�����
            m_colorToPlay = nextTurn(m_colorToPlay);

            //����ע��
            textBox1.Clear();
            textBox1.AppendText(gm.Comment);
        }
コード例 #52
0
        Point m_pos; //ZZZZZZZZZZZ ZZ ZZZ ZZZZ.

        #endregion Fields

        #region Constructors

        /**
         * ZZZZZZZZZZZ.
         */
        public GoMove(int x, int y, StoneColor sc, int seq)
        {
            m_pos = new Point(x,y);
            m_c = sc;
            m_n = seq;
            m_mr = new MoveResult();
            m_alLabel = new ArrayList();
            m_alMark = new ArrayList();
        }
コード例 #53
0
 public GoMove(String str, StoneColor c)
 {
     char cx = str[0];
     char cy = str[1];
     m_pos = new Point(0,0);
     //ZZZ Z# ZZ ZZZ ZZZZZZZZZ -
     m_pos.X = (int) ( (int)cx - (int)(char)'a');
     m_pos.Y = (int) ( (int)cy - (int)(char)'a');
     this.m_c = c;
     m_alLabel = new ArrayList();
     m_alMark = new ArrayList();
 }
コード例 #54
0
 private void appendDeadGroup(ref GoMove gm, StoneColor c)
 {
     ArrayList a = new ArrayList();
     for (int i=0; i<nSize; i++)
         for (int j=0; j<nSize; j++)
             if (Grid[i,j].isKilled())
             {
                 Point pt = new Point(i,j);
                 a.Add(pt);
                 Grid[i,j].setNoKilled();
             }
     gm.DeadGroup = a;
     gm.DeadGroupColor = c;
 }
コード例 #55
0
 public void RenderStone(Vector2f position, StoneColor color, float diameter, bool faded)
 {
     RawColor rawColor;
     switch (color)
     {
         case StoneColor.Black:
             rawColor = RawColor.Black;
             break;
         case StoneColor.White:
             rawColor = RawColor.White;
             break;
         default:
             rawColor = RawColor.Transparent;
             break;
     }
     if (faded)
         rawColor = RawColor.FromARGB(140, rawColor);
     Graphics.FillCircle(rawColor, ToGraphic(position), 0.5f * diameter*BlockSize);
 }
コード例 #56
0
 /**
  *	bury the dead stones in a group (same color).
  *	if a stone in one group is dead, the whole group is dead.
 */
 void buryTheDead(int i, int j, StoneColor c)
 {
     if (onBoard(i,j) && Grid[i,j].HasStone() &&
         Grid[i,j].Color() == c)
     {
         Grid[i,j].die();
         buryTheDead(i-1, j, c);
         buryTheDead(i+1, j, c);
         buryTheDead(i, j-1, c);
         buryTheDead(i, j+1, c);
     }
 }
コード例 #57
0
 public void setStone(StoneColor c)
 {
     if (bEmpty)
     {
         bEmpty = false;
         s.color = c;
         bUpdated = true;
     } // ZZZZ ZZZZZZ ZZZZZZZZ.
 }
コード例 #58
0
        /**
         * ZZZZZZZZZ ZZZ ZZZZZZZ ZZ ZZZ ZZZZZ, ZZZZZZZZ ZZZZ ZZZ ZZZZZ.
         */
        int calcLiberty(int x, int y, StoneColor c)
        {
            int lib = 0; // ZZZZZZZ

            if (!onBoard(x,y))
                return 0;
            if (Grid[x,y].IsScanned())
                return 0;

            if (Grid[x,y].HasStone())
            {
                if (Grid[x,y].Color() == c)
                {
                    //ZZZ ZZZZZZZZZZ ZZZ ZZZZZZZ ZZZZZ.
                    Grid[x,y].SetScanned();
                    lib += calcLiberty(x-1, y, c);
                    lib += calcLiberty(x+1, y, c);
                    lib += calcLiberty(x, y-1, c);
                    lib += calcLiberty(x, y+1, c);
                }
                else
                    return 0;
            }
            else
            {// ZZZZ ZZ ZZZZZ ZZZ ZZZZZZZZZ.
                lib ++;
                Grid[x,y].SetScanned();
            }

            return lib;
        }
コード例 #59
0
        /*
         * ZZZZ ZZZ ZZZZ ZZ ZZZZ ZZZ ZZZZ ZZZZZZZZZ ZZ ZZZZ ZZZZZZ ZZZZ ZZZZ ZZ ZZZZZZ.
         * ZZZZ ZZ ZZ:
         * 	1. ZZZZZZ ZZZ ZZZZZZZ ZZZZ ZZZZ ZZZ ZZZZZ
         *  1.1 ZZZZ ZZZZZZ ZZZ "ZZZZZZZZ" ZZZZZZZZZZ
         *	2. store the stones got killed by current move
         *  3. ZZZZZZZZZZ ZZZ ZZZ "ZZZZZZZZ"
         */
        public void PlayPrev(GoMove gm)
        {
            Point p = gm.Point;
            m_colorToPlay = gm.Color;

            clearLabelsAndMarksOnBoard();
            m_gmLastMove = gameTree.peekPrev();

            bDrawMark = true;
            Grid[p.X, p.Y].die();
            if (gm.DeadGroup != null)
            {
                foreach (Point pt in gm.DeadGroup)
                {
                    Grid[pt.X, pt.Y].setStone(gm.DeadGroupColor);
                }
            }
            optRepaint();

            //show the movement information
            textBox1.Clear();
            textBox1.AppendText(gm.Comment);
            return;
        }
コード例 #60
0
ファイル: Game.cs プロジェクト: kkawaguchi/osero
 private void ChangeNextTurnColor()
 {
     this.NextTurnColor = ChangeColor(this.NextTurnColor);
 }