コード例 #1
0
        // Move name matching stockfish command line output format (for perft comparison)
        public static string MoveName(Move move)
        {
            string from            = BoardRepresentation.SquareNameFromIndex(move.StartSquare);
            string to              = BoardRepresentation.SquareNameFromIndex(move.TargetSquare);
            string promotion       = "";
            int    specialMoveFlag = move.MoveFlag;

            switch (specialMoveFlag)
            {
            case Move.Flag.PromoteToRook:
                promotion += "r";
                break;

            case Move.Flag.PromoteToKnight:
                promotion += "n";
                break;

            case Move.Flag.PromoteToBishop:
                promotion += "b";
                break;

            case Move.Flag.PromoteToQueen:
                promotion += "q";
                break;
            }

            return(from + to + promotion);
        }
コード例 #2
0
ファイル: TDDM.cs プロジェクト: prezz/Fuzzy-Gammon
        private void Train(BoardRepresentation currentBoard, float[] target)
        {
            int race = Race(currentBoard);

            float[] input = BoardToNetworkInput(currentBoard);
            m_NeuralNetworks[race].Train(input, target, 0.00001f, 0.2f);
        }
コード例 #3
0
ファイル: BoardUI.cs プロジェクト: Pristar4/Chess-16
        private IEnumerator AnimateMove(Move move, Board board)
        {
            float       t = 0;
            const float moveAnimDuration = 0.15f;
            var         startCoord       = BoardRepresentation.CoordFromIndex(move.StartSquare);
            var         targetCoord      = BoardRepresentation.CoordFromIndex(move.TargetSquare);
            var         pieceT           = squarePieceRenderers[startCoord.fileIndex, startCoord.rankIndex].transform;
            var         startPos         = PositionFromCoord(startCoord);
            var         targetPos        = PositionFromCoord(targetCoord);

            SetSquareColour(BoardRepresentation.CoordFromIndex(move.StartSquare),
                            boardTheme.lightSquares.moveFromHighlight, boardTheme.darkSquares.moveFromHighlight);

            while (t <= 1)
            {
                yield return(null);

                t += Time.deltaTime * 1 / moveAnimDuration;
                pieceT.position = Vector3.Lerp(startPos, targetPos, t);
            }

            UpdatePosition(board);
            ResetSquareColours();
            pieceT.position = startPos;
        }
コード例 #4
0
ファイル: BoardUI.cs プロジェクト: Pristar4/Chess-16
 private void HighlightMove(Move move)
 {
     SetSquareColour(BoardRepresentation.CoordFromIndex(move.StartSquare),
                     boardTheme.lightSquares.moveFromHighlight, boardTheme.darkSquares.moveFromHighlight);
     SetSquareColour(BoardRepresentation.CoordFromIndex(move.TargetSquare),
                     boardTheme.lightSquares.moveToHighlight, boardTheme.darkSquares.moveToHighlight);
 }
コード例 #5
0
ファイル: PubevalDM.cs プロジェクト: prezz/Fuzzy-Gammon
        public override void GradeBoards(MoveRepresentationList list, BoardRepresentation initialBoard)
        {
            int  race          = 1;
            bool opponentFound = false;

            for (int i = 0; i < initialBoard.SquareCount() && race == 1; i++)
            {
                if (!opponentFound && initialBoard.GetPiecesAt(i) < 0)
                {
                    opponentFound = true;
                }

                if (opponentFound && initialBoard.GetPiecesAt(i) > 0)
                {
                    race = 0;
                }
            }

            for (int i = 0; i < list.Count(); i++)
            {
                int[] pubevalBoard = new int[28];
                MoveRepresentation currentBoard = list.GetMoveRepresentation(i);

                for (int j = 0; j < currentBoard.SquareCount(); j++)
                {
                    pubevalBoard[j] = currentBoard.GetPiecesAt(j);
                }

                pubevalBoard[26] = currentBoard.BearOffCountCurrent();
                pubevalBoard[27] = currentBoard.BearOffCountOpponent();

                double s = PubevalGrade(race, pubevalBoard);
                list.GetMoveRepresentation(i).AddScore(s);
            }
        }
コード例 #6
0
        void CreateBoardUI()
        {
            Shader squareShader = Shader.Find("Unlit/Color");

            squareRenderers      = new MeshRenderer[8, 8];
            squarePieceRenderers = new SpriteRenderer[8, 8];

            for (int rank = 0; rank < 8; rank++)
            {
                for (int file = 0; file < 8; file++)
                {
                    Transform square = GameObject.CreatePrimitive(PrimitiveType.Quad).transform;
                    square.parent   = transform;
                    square.name     = BoardRepresentation.SquareNameFromCoordinate(file, rank);
                    square.position = PositionFromCoord(file, rank, 0);
                    Material squareMaterial = new Material(squareShader);

                    squareRenderers[file, rank]          = square.gameObject.GetComponent <MeshRenderer> ();
                    squareRenderers[file, rank].material = squareMaterial;


                    SpriteRenderer pieceRenderer = new GameObject("Piece").AddComponent <SpriteRenderer> ();
                    pieceRenderer.transform.parent     = square;
                    pieceRenderer.transform.position   = PositionFromCoord(file, rank, pieceDepth);
                    pieceRenderer.transform.localScale = Vector3.one * 100 / (2000 / 6f);
                    squarePieceRenderers[file, rank]   = pieceRenderer;
                }
            }

            ResetSquareColours();
        }
コード例 #7
0
 public override void GradeBoards(MoveRepresentationList list, BoardRepresentation initialBoard)
 {
     for (int i = 0; i < list.Count(); i++)
     {
         double s = m_Random.NextDouble() - m_Random.NextDouble();
         list.GetMoveRepresentation(i).AddScore(s);
     }
 }
コード例 #8
0
 public override void GradeBoards(MoveRepresentationList list, BoardRepresentation initialBoard)
 {
     for (int i = 0; i < list.Count(); i++)
     {
         double s = m_FuzzyController.ObtainBoardStrength(list.GetMoveRepresentation(i));
         list.GetMoveRepresentation(i).AddScore(s);
     }
 }
コード例 #9
0
        private void GradePossibleMoves(MoveRepresentationList knowledgeList, BoardRepresentation initialBoard)
        {
            int evaluator = m_GUI.SelectedEvaluator();

            if (evaluator >= 0)
            {
                m_Plugins[evaluator].GradeBoards(knowledgeList, initialBoard);
            }
        }
コード例 #10
0
ファイル: TDDM.cs プロジェクト: prezz/Fuzzy-Gammon
 public override void GradeBoards(MoveRepresentationList list, BoardRepresentation initialBoard)
 {
     for (int i = 0; i < list.Count(); i++)
     {
         float[] output = Grade(list.GetMoveRepresentation(i));
         double  s      = output[0] + (2 * output[1]) + (3 * output[2]) - (2 * output[3]) - (3 * output[4]);
         list.GetMoveRepresentation(i).AddScore(s);
     }
 }
コード例 #11
0
ファイル: TDDM.cs プロジェクト: prezz/Fuzzy-Gammon
        private float[] Grade(BoardRepresentation currentBoard)
        {
            int race = Race(currentBoard);

            float[] input  = BoardToNetworkInput(currentBoard);
            float[] output = new float[5];
            m_NeuralNetworks[race].Run(input, output);
            return(output);
        }
コード例 #12
0
 public LinguisticInputValue[] Process(BoardRepresentation board)
 {
     LinguisticInputValue[] result = new LinguisticInputValue[m_PreProcessorObjects.Count];
     for (int i = 0; i < m_PreProcessorObjects.Count; i++)
     {
         result[i] = (( PreProcessingObject )m_PreProcessorObjects[i]).CreateLinguisticInputValue(board);
     }
     return(result);
 }
コード例 #13
0
ファイル: TDDM.cs プロジェクト: prezz/Fuzzy-Gammon
        public override bool AcceptDouble(BoardRepresentation board)
        {
            float[] output      = Grade(board);
            float   totalWinSum = output[0] + output[1] + output[2];

            if (totalWinSum < 0.25f)
            {
                return(false);
            }

            return(true);
        }
コード例 #14
0
        public override void GradeBoards(MoveRepresentationList list, BoardRepresentation initialBoard)
        {
            bool race = Race(initialBoard);

            for (int i = 0; i < list.Count(); i++)
            {
                Grade(list.GetMoveRepresentation(i), race, m_Output);
                float  regularLoseProberbilety = 1.0f - (m_Output[0] + m_Output[1] + m_Output[2] + m_Output[3] + m_Output[4]);
                double equity = m_Output[0] + (2 * m_Output[1]) + (3 * m_Output[2]) - regularLoseProberbilety - (2 * m_Output[3]) - (3 * m_Output[4]);
                list.GetMoveRepresentation(i).AddScore(equity);
            }
        }
コード例 #15
0
        public static int Read(int[] table, int square, bool isWhite)
        {
            if (isWhite)
            {
                var file = BoardRepresentation.FileIndex(square);
                var rank = BoardRepresentation.RankIndex(square);
                rank   = 15 - rank;
                square = rank * 16 + file;
            }

            return(table[square]);
        }
コード例 #16
0
        public void ViewBoard()
        {
            BoardRepresentation initialBoard = new BoardRepresentation(m_BgGame);

            m_MoveRepresentationGenerator.GeneratePossibleRepresentations(m_MoveRepresentationList);
            GradePossibleMoves(m_MoveRepresentationList, initialBoard);
            m_MoveRepresentationList.SortByScore();
            if (OutputMovesAndScore)
            {
                m_GUI.UpdatePossibleMovesList(m_MoveRepresentationList);
            }
        }
コード例 #17
0
    public override LinguisticInputValue CreateLinguisticInputValue(BoardRepresentation board)
    {
        LinguisticInputValue result = new LinguisticInputValue(GetName(), 0);

        float r = 0.0f;

        for (int i = 1; i < 25; i++)
        {
            if (board.GetPiecesAt(i) == 1)
            {
                bool[,] possibleDices = new bool[6, 6];
                for (int x = 0; x < 6; x++)
                {
                    for (int y = 0; y < 6; y++)
                    {
                        possibleDices[x, y] = false;
                    }
                }

                for (int j = 0; j < i; j++)
                {
                    if (board.GetPiecesAt(j) < 0)
                    {
                        CalculateHitProbability(i, j, board, possibleDices);
                    }
                }

                int waysToBeHit = 0;
                for (int x = 0; x < 6; x++)
                {
                    for (int y = 0; y < 6; y++)
                    {
                        if (possibleDices[x, y])
                        {
                            waysToBeHit++;
                        }
                    }
                }

                float p = (((float)waysToBeHit) / 36.0f) * 100;
                r += ((24.0f - ((float)i - 1)) / 24.0f) * p;
            }
        }

        if (r > 50.0f)
        {
            r = 50.0f;
        }

        result.CrispValue = (int)Math.Round(r, 0);
        return(result);
    }
コード例 #18
0
ファイル: BoardUI.cs プロジェクト: Pristar4/Chess-16
 public void UpdatePosition(Board board)
 {
     for (var rank = 0; rank < 16; rank++)
     {
         for (var file = 0; file < 16; file++)
         {
             var coord = new Coord(file, rank);
             var piece = board.Square[BoardRepresentation.IndexFromCoord(coord.fileIndex, coord.rankIndex)];
             squarePieceRenderers[file, rank].sprite             = pieceTheme.GetPieceSprite(piece);
             squarePieceRenderers[file, rank].transform.position = PositionFromCoord(file, rank, pieceDepth);
         }
     }
 }
コード例 #19
0
 private void Grade(BoardRepresentation board, bool race, float[] grade)
 {
     if (race)
     {
         SetRaceInput(board, m_RaceInput);
         m_RaceNetwork.Run(m_RaceInput, grade);
     }
     else
     {
         SetContactInput(board, m_ContactInput);
         m_ContactNetwork.Run(m_ContactInput, grade);
     }
 }
コード例 #20
0
 private void Train(BoardRepresentation board, bool race, float[] target)
 {
     if (race)
     {
         SetRaceInput(board, m_RaceInput);
         m_RaceNetwork.Train(m_RaceInput, target, MAX_SQUARE_ERROR, LEARNING_RATE);
     }
     else
     {
         SetContactInput(board, m_ContactInput);
         m_ContactNetwork.Train(m_ContactInput, target, MAX_SQUARE_ERROR, LEARNING_RATE);
     }
 }
コード例 #21
0
    public override LinguisticInputValue CreateLinguisticInputValue(BoardRepresentation board)
    {
        LinguisticInputValue result = new LinguisticInputValue(GetName(), 0);

        for (int i = 1; i < 26; i++)
        {
            if (board.GetPiecesAt(i) > 0)
            {
                result.CrispValue = i;
            }
        }
        return(result);
    }
コード例 #22
0
ファイル: TDDM.cs プロジェクト: prezz/Fuzzy-Gammon
        public override bool Double(BoardRepresentation flippedBoard)
        {
            float[] output = Grade(flippedBoard);

            float totalWinSum  = output[0] + output[1] + output[2];
            float gammonWinSum = output[1] + output[2];

            if (totalWinSum >= 0.66f && gammonWinSum < 0.5f)
            {
                return(true);
            }

            return(false);
        }
コード例 #23
0
        static public void BestMove(Move move)
        {
            string moveStr = BoardRepresentation.SquareNameFromIndex(move.StartSquare);

            moveStr += BoardRepresentation.SquareNameFromIndex(move.TargetSquare);
            // add promotion piece
            if (move.IsPromotion)
            {
                int promotionPieceType = move.PromotionPieceType;
                moveStr += PGNCreator.GetSymbolFromPieceType(promotionPieceType);
            }

            Console.WriteLine($"bestmove {moveStr}");
        }
コード例 #24
0
        public bool AcceptDouble()
        {
            if (IsAgentPlaying(m_BgGame.CurrentPlayer))
            {
                BoardRepresentation board = new BoardRepresentation(m_BgGame);

                int evaluator = m_GUI.SelectedEvaluator();
                if (evaluator >= 0)
                {
                    return(m_Plugins[evaluator].AcceptDouble(board));
                }
            }

            return(true);
        }
コード例 #25
0
        public override bool AcceptDouble(BoardRepresentation board)
        {
            bool race = Race(board);

            Grade(board, race, m_Output);

            float totalWinSum = m_Output[0] + m_Output[1] + m_Output[2];

            if (totalWinSum < 0.25f)
            {
                return(false);
            }

            return(true);
        }
コード例 #26
0
        public override bool Double(BoardRepresentation flippedBoard)
        {
            bool race = Race(flippedBoard);

            Grade(flippedBoard, race, m_Output);

            float totalWinSum  = m_Output[0] + m_Output[1] + m_Output[2];
            float gammonWinSum = m_Output[1] + m_Output[2];

            if (totalWinSum >= 0.66f && gammonWinSum < 0.5f)
            {
                return(true);
            }

            return(false);
        }
コード例 #27
0
        private void TryMakeMove(Coord startSquare, Coord targetSquare)
        {
            var startIndex  = BoardRepresentation.IndexFromCoord(startSquare);
            var targetIndex = BoardRepresentation.IndexFromCoord(targetSquare);
            var moveIsLegal = false;
            var chosenMove  = new Move();

            var moveGenerator        = new MoveGenerator();
            var wantsKnightPromotion = Input.GetKey(KeyCode.LeftAlt);

            var legalMoves = moveGenerator.GenerateMoves(board);

            for (var i = 0; i < legalMoves.Count; i++)
            {
                var legalMove = legalMoves[i];

                if (legalMove.StartSquare == startIndex && legalMove.TargetSquare == targetIndex)
                {
                    if (legalMove.IsPromotion)
                    {
                        if (legalMove.MoveFlag == Move.Flag.PromoteToQueen && wantsKnightPromotion)
                        {
                            continue;
                        }
                        if (legalMove.MoveFlag != Move.Flag.PromoteToQueen && !wantsKnightPromotion)
                        {
                            continue;
                        }
                    }

                    moveIsLegal = true;
                    chosenMove  = legalMove;
                    //	Debug.Log (legalMove.PromotionPieceType);
                    break;
                }
            }

            if (moveIsLegal)
            {
                ChoseMove(chosenMove);
                currentState = InputState.None;
            }
            else
            {
                CancelPieceSelection();
            }
        }
コード例 #28
0
ファイル: BoardUI.cs プロジェクト: Pristar4/Chess-16
        public void HighlightLegalMoves(Board board, Coord fromSquare)
        {
            if (showLegalMoves)
            {
                var moves = moveGenerator.GenerateMoves(board);

                for (var i = 0; i < moves.Count; i++)
                {
                    var move = moves[i];
                    if (move.StartSquare == BoardRepresentation.IndexFromCoord(fromSquare))
                    {
                        var coord = BoardRepresentation.CoordFromIndex(move.TargetSquare);
                        SetSquareColour(coord, boardTheme.lightSquares.legal, boardTheme.darkSquares.legal);
                    }
                }
            }
        }
コード例 #29
0
ファイル: HumanPlayer.cs プロジェクト: zeref80/Diayy-chess-2
 void HandlePieceSelection(Vector2 mousePos)
 {
     if (Input.GetMouseButtonDown(0))
     {
         if (boardUI.TryGetSquareUnderMouse(mousePos, out selectedPieceSquare))
         {
             int index = BoardRepresentation.IndexFromCoord(selectedPieceSquare);
             // Podniesienie figury jeśli jest w danym kwadracie
             if (Piece.IsColour(board.Square[index], board.ColourToMove))
             {
                 boardUI.HighlightLegalMoves(board, selectedPieceSquare);
                 boardUI.SelectSquare(selectedPieceSquare);
                 currentState = InputState.DraggingPiece;
             }
         }
     }
 }
コード例 #30
0
 private void HandlePieceSelection(Vector2 mousePos)
 {
     if (Input.GetMouseButtonDown(0))
     {
         if (boardUI.TryGetSquareUnderMouse(mousePos, out selectedPieceSquare))
         {
             var index = BoardRepresentation.IndexFromCoord(selectedPieceSquare);
             // If square contains a piece, select that piece for dragging
             if (Piece.IsColour(board.Square[index], board.ColourToMove))
             {
                 boardUI.HighlightLegalMoves(board, selectedPieceSquare);
                 boardUI.SelectSquare(selectedPieceSquare);
                 currentState = InputState.DraggingPiece;
             }
         }
     }
 }