/// <summary>
 /// Start the game, with provided board.
 /// </summary>
 /// <param name="customBoard">The abstract board that we should match, if none specified we use existing one, if none exists we generate an 8x8 board</param>
 /// <param name="mode">Which mode the game is in, player vs player, player vs engine, engine vs engine etc.</param>
 public void start(cgBoard customBoard = null, BoardMode mode = BoardMode.Undefined)
 {
     if (customBoard == null)
     {
         if (this._abstractBoard != null)
         {
             customBoard = this._abstractBoard;
         }
         else
         {
             customBoard = new global::cgBoard();
         }
     }
     if (displayAs3d)
     {
         Camera.main.transform.localPosition = new Vector3(0, -2.28f, -12.58f);
         Quaternion newQuat = Camera.main.transform.localRotation;
         newQuat = Quaternion.Euler(-23.46f, newQuat.eulerAngles.y, newQuat.eulerAngles.z);
         Camera.main.transform.localRotation = newQuat;
     }
     //customBoard = customBoard.revertToStart();
     UnityEngine.Debug.Log("start: ");
     _squares = getSquares();
     Mode     = (mode != BoardMode.Undefined ? mode : Mode);
     _engine  = new cgEngine(searchDepthWeak, searchDepthStrong);
     setBoardTo(customBoard);
     //_abstractBoard.readBoard();
     // UnityEngine.Debug.Log(_abstractBoard.boardToString());
     if (Mode == BoardMode.PlayerVsEngine && !whiteTurnToMove)
     {
         MakeEngineMove(_abstractBoard.duplicate(), false, _engineCallback);
     }
     else if (Mode == BoardMode.EngineVsPlayer && whiteTurnToMove)
     {
         MakeEngineMove(_abstractBoard.duplicate(), true, _engineCallback);
     }
     else if (Mode == BoardMode.EngineVsEngine)
     {
         MakeEngineMove(_abstractBoard.duplicate(), true, _engineCallback);
     }
 }
Beispiel #2
0
    /// <summary>
    /// Writes the full game notation from the current moves stored in Moves list.
    /// </summary>
    /// <param name="type">What notationtype should it be?</param>
    /// <param name="formatType">Should it be PGN format or not?</param>
    /// <returns>A string with full game notation.</returns>
    public string writeFullNotation(NotationType type, FormatType formatType = FormatType.None)
    {
        string  str = "";
        cgBoard disambiguationBoard = board.duplicate().revertToStart();

        if (type == NotationType.Coordinate)
        {
            foreach (cgSimpleMove pcem in moves)
            {
                str += (disambiguationBoard.SquareNames[pcem.from] + "-" + disambiguationBoard.SquareNames[pcem.to]) + " ";
            }
        }
        if (formatType == FormatType.PGN)
        {
            string q = "\"";
            str  = " [Event " + q + "Pro Chess" + q + "]\n";
            str += " [Site " + q + "Undefined site" + q + "]\n";
            str += " [Date " + q + DateTime.Now + q + "]\n";
            str += " [White " + q + "Chessplayer1" + q + "]\n";
            str += " [Black " + q + "Chessplayer2" + q + "]\n";
            str += " [Result " + q + "1/2-1/2" + q + "]\n";
        }
        if (type == NotationType.Algebraic)
        {
            foreach (cgSimpleMove pcem in moves)
            {
                if (disambiguationBoard.moves.Count % 2 == 0)
                {
                    str += (Math.Floor(disambiguationBoard.moves.Count / 2f) + 1).ToString() + ". ";
                }

                int typ = Math.Abs(disambiguationBoard.squares[pcem.from]);
                List <cgSimpleMove> othermoves     = disambiguationBoard.findLegalMoves(disambiguationBoard.whiteTurnToMove);
                List <cgSimpleMove> ambiguousMoves = new List <cgSimpleMove>();
                foreach (cgSimpleMove othermove in othermoves)
                {
                    if (othermove.to == pcem.to && othermove.from != pcem.from && Math.Abs(disambiguationBoard.squares[othermove.from]) == typ)
                    {
                        ambiguousMoves.Add(othermove);
                    }
                }
                if (typ == 1 && pcem.capturedType != 0)
                {
                    str += disambiguationBoard.SquareNames[pcem.from].Substring(0, 1);
                }
                if (typ == 2)
                {
                    str += "R";
                }
                if (typ == 3)
                {
                    str += "N";
                }
                if (typ == 4)
                {
                    str += "B";
                }
                if (typ == 5)
                {
                    str += "Q";
                }
                if (typ == 6 && !(pcem is cgCastlingMove))
                {
                    str += "K";
                }
                //if (typ == 6) str += "K";

                if (ambiguousMoves.Count > 0 && typ != 1)
                {
                    bool fileMatch = false;
                    bool rankMatch = false;
                    foreach (cgSimpleMove ambiguousMove in ambiguousMoves)
                    {
                        if (disambiguationBoard.SquareNames[ambiguousMove.from].Substring(0, 1) == disambiguationBoard.SquareNames[pcem.from].Substring(0, 1))
                        {
                            fileMatch = true;
                        }
                        if (disambiguationBoard.SquareNames[ambiguousMove.from].Substring(1, 1) == disambiguationBoard.SquareNames[pcem.from].Substring(1, 1))
                        {
                            rankMatch = true;
                        }
                    }
                    if (!fileMatch)
                    {
                        str += disambiguationBoard.SquareNames[pcem.from].Substring(0, 1);
                    }
                    else if (fileMatch && !rankMatch)
                    {
                        str += disambiguationBoard.SquareNames[pcem.from].Substring(1, 1);
                    }
                    else if (fileMatch && rankMatch)
                    {
                        str += disambiguationBoard.SquareNames[pcem.from];
                    }
                }
                if (pcem.capturedType != 0)
                {
                    str += "x";
                }
                if (pcem is cgCastlingMove)
                {
                    if (pcem.to == 2 || pcem.to == 58)
                    {
                        str += "O-O-O";
                    }
                    else
                    {
                        str += "O-O";
                    }
                }
                else
                {
                    str += disambiguationBoard.SquareNames[pcem.to];
                }
                if (pcem.queened)
                {
                    str += "=Q";
                }
                str += " ";
                disambiguationBoard.move(pcem);
            }
        }

        return(str);
    }