Пример #1
0
        public bool PlayStone(int index, Color color, bool allowUndo)
        {
            if (!IsLegal(index, color))
            {
                return(false);
            }

            if (allowUndo)
            {
                UndoStack.Mark();
                UndoStack.Add(new GoBoardUndoState(this));
            }
            else
            {
                UndoStack.Clear();
            }

            if (index == CoordinateSystem.RESIGN)
            {
                GameOver = true;
            }

            if ((index == CoordinateSystem.PASS) && (LastMove == CoordinateSystem.PASS) && (MoveNbr > 0))
            {
                GameOver = true;
            }

            ColorEnclosedRegions = null;
            SafetyStatusMap      = null;

            // set turn
            Turn     = color;
            LastMove = index;
            MoveList.Add(new KeyValuePair <Color, int>(color, index));

            // save hash
            if (LastMove != CoordinateSystem.PASS)
            {
                if (!ZobrishHashes.ContainsKey(ZobristHash))
                {
                    ZobrishHashes.Add(ZobristHash.Clone(), MoveNbr);
                }
            }

            // increment move number
            MoveNbr++;

            //			Console.WriteLine("# " + MoveNbr + " " + color.ToString() + " " + Coord.ToString(index));
            //			Dump();

            SimpleKoPoint = CoordinateSystem.PASS;

            if (!(index == CoordinateSystem.PASS) || (index == CoordinateSystem.RESIGN))
            {
                // update blocks
                ExecutePlay(index, color, allowUndo);
            }

            //#if DEBUG
            //			if (!_SelfTest())
            //				Console.WriteLine("GoBoard::_SelfTest() Failed");
            //#endif

            return(true);
        }