Пример #1
0
    public static bool CanMakeMove(OthelloPiece[,] bricks, Othello.PlayerColor currentPlayer)
    {
        int i = 0;
        foreach (OthelloPiece brick in bricks)
        {
            i++;

            if (brick.brickColor == BrickColor.Black || brick.brickColor == BrickColor.White)
            {
                continue;
            }

            foreach (Direction direction in Enum.GetValues(typeof(Direction)))
            {
                OthelloPiece nextBrick = NextBrickInDirection(brick.x, brick.y, direction, bricks);
                if (nextBrick != null)
                {
                    if (ValidateLine(nextBrick.x, nextBrick.y, direction, 1, bricks, currentPlayer))
                    {
                        return true;
                    }
                }
            }
        }
        return false;
    }
Пример #2
0
        private async void Initcpu(int cpu, int playercolor)
        {
            Ai = new MakeOthelloAi(cpu);

            for (var i = 0; i < DiscDataList.Length; i++)
            {
                var discdata = new DiscViewModel(i, Height * 0.08);
                discdata.DiscTapedCommand = new SimpleCommand((async o =>
                {
                    if (!Othello.Put(ConvertPoint(discdata.Number)))
                    {
                        return;
                    }
                    var points = Update();
                    await AiPutAsync(points);
                }));
                DiscDataList[i] = discdata;
            }

            if (playercolor == 1)
            {
                var points = Update();
                await AiPutAsync(points);
            }
            else
            {
                Update();
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            BoardPrinter printer = new BoardPrinter();

            var othello = new Othello();

            othello.Start(Color.White);

            othello.Set(3, 3);
            othello.Set(3, 4);
            othello.Set(4, 4);
            othello.Set(4, 3);

            printer.Print("オリジナル", othello);

            var snapshot = othello.Save();

            // 適当に石を追加しておく
            othello.Set(1, 1);
            othello.Set(5, 5);
            othello.Set(7, 7);

            printer.Print("オリジナル(追加後)", othello);

            // 復元
            var replay = new Othello();

            replay.Load(snapshot);
            printer.Print("復元", replay);
        }
Пример #4
0
 void Awake()
 {
     try
     {
         othello = GameObject.Find("Othello").GetComponent<Othello>();
     }
     catch
     {
     }
     anim = GetComponent<Animator>();
 }
Пример #5
0
 public Othello(Othello ttt)
 {
     for (int i = 0; i < 8; i++)
     {
         for (int j = 0; j < 8; j++)
         {
             Board[i, j] = ttt.Board[i, j];
         }
     }
     player = ttt.player;
 }
Пример #6
0
    IEnumerator moveBlack(float Count)
    {
        yield return(new WaitForSeconds(Count));

        Othello ttt = new Othello(gameState);

        tn = new TreeNode(ttt);

        test();

        TreeNode BC    = tn.bestChild();
        int      index = BC.lastMove;
        int      col   = index / 8;
        int      row   = index % 8;

        if (gameState.Board[col, row] == 0 && gameState.CheckClosed(gameState.Board, col, row, false))
        {
            gameState.Board[col, row] = gameState.whoseMove();
        }

        if (gameState.whoseMove() == 1)
        {
            m_Buttons[index].image.color = Color.black;
        }
        else if (gameState.whoseMove() == 2)
        {
            m_Buttons[index].image.color = Color.white;
        }

        drawBoard(gameState);
        gameState.NextTurn();

        if (gameState.CanMove(gameState.Board) == false)
        {
            gameState.NextTurn();

            if (gameState.CanMove(gameState.Board) == false)
            {
                End();
            }
            else
            {
                StartCoroutine("moveBlack", bwaitTime);
            }
        }
        else
        {
            StartCoroutine("moveWhite", waitTime);
        }
        yield return(null);
    }
Пример #7
0
    public void drawBoard(Othello gs)
    {
        int[] changedButtons = new int[64];
        int   buttonIndex    = 0;

        int blackPoints = gameState.CountPoints(gameState.Board, 1);
        int whitePoints = gameState.CountPoints(gameState.Board, 2);

        string scoreBlack = blackPoints.ToString();
        string scoreWhite = whitePoints.ToString();

        pointsBlackT.text = scoreBlack;
        pointsWhiteT.text = scoreWhite;

        for (int i = 0; i < m_Buttons.Length; i++)
        {
            int col = i / 8;
            int row = i % 8;

            m_Buttons[i].GetComponent <Button>().interactable = false;

            if (gs.Board[col, row] != 0)
            {
                changedButtons[buttonIndex] = i;
                buttonIndex++;
            }
        }

        for (int i = 0; i < buttonIndex; i++)
        {
            int index = changedButtons[i];
            int col   = index / 8;
            int row   = index % 8;

            if (gs.Board[col, row] == 1)
            {
                m_Buttons[index].image.color = Color.black;
            }
            else if (gs.Board[col, row] == 2)
            {
                m_Buttons[index].image.color = Color.white;
            }
        }

        foreach (var button in m_Buttons)
        {
            button.GetComponent <Button>().interactable = true;
        }
    }
Пример #8
0
    // Use this for initialization
    void Start()
    {
        endText         = GameObject.Find("EndText").GetComponent <Text>();
        endText.enabled = false;
        endPanel        = GameObject.Find("EndPanel");
        endPanel.SetActive(false);

        pointsBlackT = GameObject.Find("TBlack").GetComponent <Text>();
        pointsWhiteT = GameObject.Find("TWhite").GetComponent <Text>();

        whoPlay     = GameObject.Find("WhoPlay").GetComponent <Button>();
        simulations = GameObject.Find("InputField").GetComponent <InputField>();
        startPanel  = GameObject.Find("StartPanel");

        gameState = new Othello();
    }
Пример #9
0
    public static void FlashRow(OthelloPiece brick, Direction direction, OthelloPiece[,] bricks, Othello.PlayerColor currentPlayer)
    {
        int X = brick.x;
        int Y = brick.y;
        if ((currentPlayer == Othello.PlayerColor.White && bricks[X, Y].brickColor == BrickColor.Black) || (currentPlayer == Othello.PlayerColor.Black && bricks[X, Y].brickColor == BrickColor.White))
        {
            Flash(brick);

            brick = NextBrickInDirection(X, Y, direction, bricks);
            FlashRow(brick, direction, bricks, currentPlayer);
        }
        else
        {
            return;
        }
    }
Пример #10
0
 public static ArrayList GetAllValidMoves(OthelloPiece[,] bricks, Othello.PlayerColor currentPlayer)
 {
     ArrayList validMoves = new ArrayList();
     ArrayList validDirections;
     foreach (OthelloPiece brick in bricks)
     {
         if (brick.brickColor == BrickColor.Empty || brick.brickColor == BrickColor.Hint)
         {
             validDirections = GetValidDirections(bricks, brick, currentPlayer);
             if (validDirections.Count > 0)
             {
                 validMoves.Add(brick);
             }
         }
     }
     return validMoves;
 }
Пример #11
0
 private void Initplayer()
 {
     for (var i = 0; i < DiscDataList.Length; i++)
     {
         var discdata = new DiscViewModel(i, Height * 0.08);
         discdata.DiscTapedCommand = new SimpleCommand((o =>
         {
             if (!Othello.Put(ConvertPoint(discdata.Number)))
             {
                 return;
             }
             Update();
         }));
         DiscDataList[i] = discdata;
     }
     Update();
 }
    public static List<Brick> GetAllValidMoves(Brick[,] board, Othello.PlayerColor currentPlayer)
    {
        var validMoves = new List<Brick>();
        List<Direction> validDirections;
        foreach (Brick brick in board)
        {
            if (brick.brickColor == BrickColor.Empty || brick.brickColor == BrickColor.Hint)
            {

                validDirections = GetValidDirections(board, brick, currentPlayer);
                if (validDirections.Count > 0)
                {
                    validMoves.Add(brick);
                }
            }
        }
        return validMoves;
    }
Пример #13
0
 public void CheckArrows(Othello.PlayerColor playerColor)
 {
     if (playerColor == Othello.PlayerColor.White)
     {
         whiteArrow.SetActive(true);
         blackArrow.SetActive(false);
     }
     else if (playerColor == Othello.PlayerColor.Black)
     {
         whiteArrow.SetActive(false);
         blackArrow.SetActive(true);
     }
     else
     {
         whiteArrow.SetActive(false);
         blackArrow.SetActive(false);
     }
 }
Пример #14
0
        public void StartOtheloFormsGame()
        {
            GameSettingsForm gameSettingsForm         = new GameSettingsForm();
            DialogResult     gameSettingsWindowResult = gameSettingsForm.ShowDialog();

            if (gameSettingsWindowResult != DialogResult.Cancel)
            {
                m_BoardUiForm = new BoardForm(gameSettingsForm.RequestedBoardSize);

                m_OtheloGame = new Othello();
                m_OtheloGame.m_BoardChangedDelegate         += m_OtheloGame_BoardChanged;
                m_OtheloGame.m_CurrentPlayerChangedDelegate += m_BoardUiForm.PlayerChanged;
                m_OtheloGame.m_GameFinishedDelegate         += m_OtheloGame_GameFinished;
                m_BoardUiForm.PlayerSelected += new TokenClickEventHandler(player_Selected_EventHandler);
                m_OtheloGame.SetInitialSettings(gameSettingsForm.RequestedBoardSize, gameSettingsForm.IsComputerOpponent, null, null);
                m_BoardUiForm.ShowDialog();
            }
        }
Пример #15
0
    public double rollOut(TreeNode tn)
    {
        Othello   rollGS       = new Othello(tn.gameState);
        bool      stillPlaying = true;
        double    rc           = 0;
        int       moveIndex;
        ArrayList am = rollGS.availableMoves();

        while (am.Count > 0 && stillPlaying)
        {
            moveIndex = r.Next(0, am.Count);

            int move = (int)am[moveIndex];
            rollGS.makeMove(move);

            rollGS.NextTurn();

            if (rollGS.CanMove(rollGS.Board) == false)
            {
                rollGS.NextTurn();

                if (rollGS.CanMove(rollGS.Board) == false)
                {
                    stillPlaying = false;
                    int blackPoints = rollGS.CountPoints(rollGS.Board, 1);
                    int whitePoints = rollGS.CountPoints(rollGS.Board, 2);

                    if (blackPoints > whitePoints)
                    {
                        rc = 1.0;
                    }
                    else if (blackPoints <= whitePoints)
                    {
                        rc = 0.0;
                    }
                }
            }
            am = rollGS.availableMoves();
        }

        return(rc);
    }
Пример #16
0
        private List <Point> Update()
        {
            for (var i = 0; i < 64; i++)
            {
                var point = ConvertPoint(i);
                switch (Othello.Board[point.x, point.y])
                {
                case -1:
                    DiscDataList[i].DiscCondition = DiscCondition.Black;
                    break;

                case 1:
                    DiscDataList[i].DiscCondition = DiscCondition.White;
                    break;

                case 0:
                    DiscDataList[i].DiscCondition = DiscCondition.Void;
                    break;
                }
            }
            var points = Othello.GetPossiblePoints(Othello.Turn);

            switch (Othello.Turn)
            {
            case -1:
                foreach (var point in points)
                {
                    DiscDataList[ConvertInt(point)].DiscCondition = DiscCondition.AbleBlack;
                }
                break;

            case 1:
                foreach (var point in points)
                {
                    DiscDataList[ConvertInt(point)].DiscCondition = DiscCondition.AbleWhite;
                }
                break;
            }
            BlackNumberText = Othello.GetDiscNumber(-1).ToString();
            WhiteNumberText = Othello.GetDiscNumber(1).ToString();
            return(points);
        }
Пример #17
0
    static void Main(string[] args)
    {
        int id        = int.Parse(Console.ReadLine()); // id of your player.
        int boardSize = int.Parse(Console.ReadLine());

        Console.Error.WriteLine("ID " + id + " size " + boardSize);

        // game loop
        while (true)
        {
            // rows from top to bottom (viewer perspective)
            var lines = new List <string> ();
            for (int i = 0; i < boardSize; i++)
            {
                string line = Console.ReadLine();
                Console.Error.WriteLine(line);
                lines.Add(line);
            }
            // number of legal actions for this turn
            var actions     = new List <string> ();
            int actionCount = int.Parse(Console.ReadLine());
            for (int i = 0; i < actionCount; i++)
            {
                // the action
                string action = Console.ReadLine();
                Console.Error.WriteLine(action);
                actions.Add(action);
            }
            Console.Error.WriteLine("-----");

            // a-h1-8
            //string bestAction = actions.OrderByDescending(a => evaluateMove(a)).First();
            //Console.WriteLine(bestAction);
            //
            Othello o    = new Othello(lines.ToArray());
            string  move = o.PlayNextMove(id);

            //
            Console.WriteLine(move);
        }
    }
Пример #18
0
        static void PlayGame()
        {
            IGame state   = new Othello();
            var   player1 = new ConsolePlayer()
            {
                Name = "Player 1"
            };
            //var player1 = new MonteCarloTreeSearchPlayer(1000) { Name = "Player 1" };
            var player2 = new MonteCarloTreeSearchPlayer(1000)
            {
                Name = "Player 2"
            };
            var playerLookup = new Dictionary <PlayerId, IPlayer>()
            {
                { PlayerId.Player1, player1 },
                { PlayerId.Player2, player2 },
            };
            PlayerId winner;

            while (!state.IsTerminal(out winner))
            {
                ConsolePlayer.GetBoardRepresentation((dynamic)state, Console.Out);
                var currentPlayer = playerLookup[state.CurrentPlayersTurn];
                state = currentPlayer.MakeMove(state, state.ExpandSuccessors());
                Console.WriteLine(currentPlayer.Name + " selected " + state.DescribeLastMove() + ".");
                Console.WriteLine();
            }
            Console.WriteLine("THE GAME IS OVER!");
            ConsolePlayer.GetBoardRepresentation((dynamic)state, Console.Out);
            if (winner == PlayerId.None)
            {
                Console.WriteLine("THE GAME WAS A TIE!");
            }
            else
            {
                Console.WriteLine("THE WINNER IS " + playerLookup[winner].Name + "!");
            }
        }
Пример #19
0
    // Use this for initialization
    void Start()
    {
        endText         = GameObject.Find("EndText").GetComponent <Text>();
        endText.enabled = false;

        endPanel = GameObject.Find("EndPanel");
        endPanel.SetActive(false);

        pointsBlackT = GameObject.Find("TBlack").GetComponent <Text>();
        pointsWhiteT = GameObject.Find("TWhite").GetComponent <Text>();

        whoPlay = GameObject.Find("WhoPlay").GetComponent <Button>();

        simulations = GameObject.Find("InputField").GetComponent <InputField>();
        startPanel  = GameObject.Find("StartPanel");

        gameState = new Othello();

        foreach (var button in m_Buttons)
        {
            button.onClick.AddListener(() => Move(button.name));
        }
    }
Пример #20
0
    public void BroadcastMyTurn(OthelloPiece[,] bricks, Othello.PlayerColor currentPlayerColor)
    {
        _othelloPacket = bricks.ToByteArray();

        BroadcastMyTime();
        PlayGamesPlatform.Instance.RealTime.SendMessageToAll(true, _othelloPacket);
    }
Пример #21
0
 void Awake()
 {
     anim = GetComponent<Animator>();
     othello = GameObject.Find("Othello").GetComponent<Othello>();
     cantMoveText = GameObject.Find("CantMoveText").GetComponent<Text>();
     parentRectTransform = GameObject.Find("CantMovePanelParent").GetComponent<RectTransform>();
 }
Пример #22
0
    public void OutOfTimeWin(Othello.PlayerColor looser)
    {
        string winText = "Congratulations ";
        print("Looser! " + looser);
        if (OthelloManager.Instance.PlayingOnline)
        {
            bool isWinner = looser == OthelloManager.Instance.PlayerColor ? false : true;

            winText = isWinner ? "Congratulations, you won!" : "You lost!";
        }
        else
        {
            if (looser == Othello.PlayerColor.White)
            {
                winText += BlackWon();
            }
            else
            {
                winText += WhiteWon();
            }
        }
        cantMoveText.text = winText;
        anim.SetTrigger(TRIGGER_SWIPE_IN);
    }
Пример #23
0
 public TreeNode(Othello ttt)
 {
     gameState = new Othello(ttt);
 }
Пример #24
0
 public OthelloForm()
 {
     _game = new Othello(new Human(), new ForesightAI(3));
     InitializeComponent();
     InitializeButtons();
 }
 public static void PutDownBrick(ref Brick[,] board, Brick brick, Othello.PlayerColor currentPlayer)
 {
     board[brick.position.x, brick.position.y].brickColor = currentPlayer ==
         Othello.PlayerColor.White ? board[brick.position.x, brick.position.y].brickColor = BrickColor.White : brick.brickColor = BrickColor.Black;
 }
    public static List<Direction> GetValidDirections(Brick[,] bricks, Brick brick, Othello.PlayerColor currentPlayer)
    {
        var pos = brick.position;

        var validDirections = new List<Direction>();
        foreach (Direction direction in Enum.GetValues(typeof(Direction)))
        {
            Brick? tempNextBrick = NextBrickInDirection(pos.x, pos.y, direction, bricks);

            if (tempNextBrick.HasValue)
            {
                var nextBrick = (Brick)tempNextBrick.Value;
                var nextPos = nextBrick.position;
                if (ValidateLine(nextPos.x, nextPos.y, direction, 1, bricks, currentPlayer))
                {
                    validDirections.Add(direction);
                }
            }
        }
        return validDirections;
    }
 public static void TurnRow(Brick brick, Direction direction, ref Brick[,] board, Othello.PlayerColor currentPlayer)
 {
     int x = brick.position.x;
     int y = brick.position.y;
     if ((currentPlayer == Othello.PlayerColor.White && board[x, y].brickColor == BrickColor.Black) || (currentPlayer == Othello.PlayerColor.Black && board[x, y].brickColor == BrickColor.White))
     {
         Turn(ref board, brick);
         var tempBrick = NextBrickInDirection(x, y, direction, board);
         if (tempBrick.HasValue)
         {
             brick = tempBrick.Value;
         }
         TurnRow(brick, direction, ref board, currentPlayer);
     }
     else
     {
         return;
     }
 }
Пример #28
0
 public static ArrayList GetValidDirections(OthelloPiece[,] bricks, OthelloPiece brick, Othello.PlayerColor currentPlayer)
 {
     //	print ("Checking Valid Moves");
     ArrayList validDirections = new ArrayList();
     foreach (Direction direction in Enum.GetValues(typeof(Direction)))
     {
         OthelloPiece nextBrick = NextBrickInDirection(brick.x, brick.y, direction, bricks);
         if (nextBrick != null)
         {
             //print ("valid move: X." + nextBrick.x + " Y. " + nextBrick.y + " in direction " + direction);
             if (ValidateLine(nextBrick.x, nextBrick.y, direction, 1, bricks, currentPlayer))
             {
                 validDirections.Add(direction);
             }
         }
     }
     return validDirections;
 }
 static bool ValidateLine(int x, int y, Direction direction, int step, Brick[,] board, Othello.PlayerColor currentPlayer)
 {
     //Here we want to get a complete Othello Line. Where
     int max = board.GetLength(0) - 1;
     //if outside the board return false
     if (x < 0 || x > max || y < 0 || y > max)
     {
         //	print (direction + " Next brick is OUTSIDE!");
         return false;
     }
     //if empty return false
     else if (IsEmpty(board[x, y]))
     {
         //print (direction + " Next brick is EMPTY!");
         return false;
     }
     //if has stepped over atleast 1 of opponents bricks and now finds your own color. Returns true and validates the move as a valid move.
     else if (step > 1 && ((currentPlayer == Othello.PlayerColor.Black && board[x, y].brickColor == BrickColor.Black) || (currentPlayer == Othello.PlayerColor.White && board[x, y].brickColor == BrickColor.White)))
     {
         //	print (direction + " Next brick makes the line VALID!");
         return true;
     }
     //if first checked brick is the same color return false
     else if (step == 1 && ((currentPlayer == Othello.PlayerColor.Black && board[x, y].brickColor == BrickColor.Black) || (currentPlayer == Othello.PlayerColor.White && board[x, y].brickColor == BrickColor.White)))
     {
         //	print (direction + " Next brick on the first step is the same color!");
         return false;
     }
     else
     {
         //	print (direction + " CONTINUING for next Validation");
         Brick? tempBrick = NextBrickInDirection(x, y, direction, board);
         if (tempBrick.HasValue)
         {
             Brick brick = tempBrick.Value;
             var brickPos = brick.position;
             step += 1;
             return ValidateLine(brickPos.x, brickPos.y, direction, step, board, currentPlayer);
         }
         else
         {
             return false;
         }
     }
 }
    private static void MakeMove(ref Brick[,] board, Brick brick, Othello.PlayerColor currentColor)
    {
        List<Direction> validDirections;
        validDirections = GetValidDirections(board, brick, currentColor);
        if (validDirections.Count > 0)
        {
            PutDownBrick(ref board, brick, currentColor);
            for (int i = 0; i < validDirections.Count; i++)
            {
                Direction direction = validDirections[i];
                Brick? tempNextBrick = NextBrickInDirection(brick.position.x, brick.position.y, direction, board);
                if (tempNextBrick.HasValue)
                {
                    var nextBrick = tempNextBrick.Value;
                    TurnRow(nextBrick, direction, ref board, currentColor);
                }
            }

        }
    }
Пример #31
0
    static bool ValidateLine(int X, int Y, Direction direction, int step, OthelloPiece[,] bricks, Othello.PlayerColor currentPlayer)
    {
        //Here we want to get a complete Othello Line. Where
        int max = (int)Mathf.Sqrt(bricks.Length);
        max--;

        //if outside the board return false
        if (X < 0 || X > max || Y < 0 || Y > max)
        {
            //	print (direction + " Next brick is OUTSIDE!");
            return false;
        }
        //if empty return false
        else if (IsEmpty(bricks[X, Y]))
        {
            //print (direction + " Next brick is EMPTY!");
            return false;
        }
        //if has stepped over atleast 1 of opponents bricks and now finds your own color. Returns true and validates the move as a valid move.
        else if (step > 1 && ((currentPlayer == Othello.PlayerColor.Black && bricks[X, Y].brickColor == BrickColor.Black) || (currentPlayer == Othello.PlayerColor.White && bricks[X, Y].brickColor == BrickColor.White)))
        {
            //	print (direction + " Next brick makes the line VALID!");
            return true;
        }
        //if first checked brick is the same color return false
        else if (step == 1 && ((currentPlayer == Othello.PlayerColor.Black && bricks[X, Y].brickColor == BrickColor.Black) || (currentPlayer == Othello.PlayerColor.White && bricks[X, Y].brickColor == BrickColor.White)))
        {
            //	print (direction + " Next brick on the first step is the same color!");
            return false;
        }
        else
        {
            //	print (direction + " CONTINUING for next Validation");
            OthelloPiece brick = NextBrickInDirection(X, Y, direction, bricks);
            if (brick != null)
            {
                step += 1;
                return ValidateLine(brick.x, brick.y, direction, step, bricks, currentPlayer);
            }
            else
            {
                //		print (direction + " Reached the end, not a valid direction");
                return false;
            }
        }
    }
Пример #32
0
    public static void PutDownBrick(OthelloPiece brick, Othello.PlayerColor currentPlayer)
    {
        if (currentPlayer == Othello.PlayerColor.White)
        {
            brick.brickColor = BrickColor.White;
        }
        else
        {
            brick.brickColor = BrickColor.Black;

        }
    }
    public static OthelloPiece GetMoveWithLeastOpponentMoves(OthelloPiece[,] bricks, List<OthelloPiece> possibleMoves, Othello.PlayerColor currentColor)
    {
        var chosenBrick = new Brick(new Position(0, 0), BrickColor.Empty);

        var opponentColor = currentColor == Othello.PlayerColor.Black ? Othello.PlayerColor.White : Othello.PlayerColor.Black;

        var reservIndexex = new List<int>();
        var bestNumberOfOpponentReserveMoves = int.MaxValue;
        var chosenIndexex = new List<int>();
        var index = 0;
        int bestNumberOfOppenentMoves = int.MaxValue;
        foreach (var brick in possibleMoves)
        {
            var board = MakeCopyOfBricks(bricks);
            Brick tempBrick = board[brick.x, brick.y];
            MakeMove(ref board, tempBrick, currentColor);
            List<Brick> allValidMoves = GetAllValidMoves(board, opponentColor);
            bool opponentCanTakeCorner = false;
            opponentCanTakeCorner = CheckIfOpponentCanTakeACorner(allValidMoves);

            if (opponentCanTakeCorner)
            {
                int numberOfReservMoves = allValidMoves.Count;

                if (numberOfReservMoves == bestNumberOfOpponentReserveMoves)
                {
                    reservIndexex.Add(index);
                }
                else if (numberOfReservMoves < bestNumberOfOpponentReserveMoves)
                {
                    bestNumberOfOpponentReserveMoves = numberOfReservMoves;
                    reservIndexex.Clear();
                    reservIndexex.Add(index);
                }
                index++;
                Debug.Log("If I take " + brick.x + " , " + brick.y + " you will have " + numberOfReservMoves + " number of possible moves. But you can take the corner");
                continue;
            }

            int numberOfOpponentMoves = allValidMoves.Count;

            Debug.Log("If I take " + brick.x + " , " + brick.y + " you will have " + numberOfOpponentMoves + " number of possible moves.");

            if (numberOfOpponentMoves == bestNumberOfOppenentMoves)
            {
                chosenIndexex.Add(index);
            }
            else if (numberOfOpponentMoves < bestNumberOfOppenentMoves)
            {
                bestNumberOfOppenentMoves = numberOfOpponentMoves;
                chosenIndexex.Clear();
                chosenIndexex.Add(index);
            }

            index++;
        }

        Debug.Log("I got " + chosenIndexex.Count + " best moves to choose from.");
        int chosenIndex = 0;
        if (chosenIndexex.Count > 0)
        {
            chosenIndex = chosenIndexex[UnityEngine.Random.Range(0, chosenIndexex.Count - 1)];
            Debug.Log("Sorry, but I chose " + possibleMoves[chosenIndex].x + " , " + possibleMoves[chosenIndex].y + " for you to only have " + bestNumberOfOppenentMoves + " moves next turn");
        }
        else
        {
            chosenIndex = reservIndexex[UnityEngine.Random.Range(0, reservIndexex.Count - 1)];
            Debug.Log("Sorry, but I chose " + possibleMoves[chosenIndex].x + " , " + possibleMoves[chosenIndex].y + " for you to only have " + bestNumberOfOppenentMoves + " moves next turn. But you can take the corner....");

        }
        return possibleMoves[chosenIndex];
    }
Пример #34
0
 // Start is called before the first frame update
 private void Start()
 {
     _othello = this.GetComponent <Othello>();
 }
Пример #35
0
        public BoardViewModel(int player = -1, int cpu = 0)
        {
            WaitingMaskVisibility = Visibility.Collapsed;
            MessageBoxData        = MessageBoxViewModel.Empty;
            PassControlData       = new PassControlViewModel();
            DiscDataList          = new DiscViewModel[64];


            double min = Math.Min(Frame.ActualHeight, Frame.ActualWidth);

            if (min < 600)
            {
                Height = min * 5 / 6;
                Width  = min * 5 / 6;
            }
            else
            {
                Height = 500;
                Width  = 500;
            }
            cpuLevel    = cpu;
            playercolor = player;
            Othello     = new Othello();
            Othello.Start();
            QuitCommand = new SimpleCommand(o =>
            {
                MessageBoxData = new ConfirmMessageBoxViewModel();
            });


            BlackNumberText = Othello.GetDiscNumber(-1).ToString();
            WhiteNumberText = Othello.GetDiscNumber(1).ToString();
            if (cpu == 0)
            {
                BlackPlayerText = "1P: ";
                WhitePlayerText = "2P: ";
                BackCommand     = new SimpleCommand(o =>
                {
                    Othello.Back();
                    Update();
                });
                Othello.EndEvent += (othello, resulut) =>
                {
                    if (resulut == 0)
                    {
                        MessageBoxData = new EndMessageBoxViewModel(player, cpu, "Draw !");
                    }
                    else if (playercolor == resulut)
                    {
                        MessageBoxData = new EndMessageBoxViewModel(player, cpu, "2P Success");
                    }
                    else
                    {
                        MessageBoxData = new EndMessageBoxViewModel(player, cpu, "2P Success");
                    }
                };
                PassControlData.OkCommand = new SimpleCommand(o =>
                {
                    PassControlData.Visibility = Visibility.Collapsed;
                    Othello.Pass();
                    Update();
                });
                Othello.PassEvent += (othello, pass) =>
                {
                    PassControlData.Visibility = Visibility.Visible;
                };
                Initplayer();
            }
            else
            {
                if (player == 1)
                {
                    BlackPlayerText = "CPU Lv." + cpu + ":";
                    WhitePlayerText = "You:";
                }
                else
                {
                    WhitePlayerText = "CPU Lv." + cpu + ":";
                    BlackPlayerText = "You:";
                }

                BackCommand = new SimpleCommand(o =>
                {
                    PassControlData.Visibility = Visibility.Collapsed;
                    Othello.Back();
                    Othello.Back();
                    Update();
                });
                Othello.EndEvent += (othello, resulut) =>
                {
                    if (resulut == 0)
                    {
                        MessageBoxData = new EndMessageBoxViewModel(player, cpu, "Draw !");
                    }
                    else if (playercolor == resulut)
                    {
                        MessageBoxData = new LoseMessageBoxViewModel(player, cpu);
                    }
                    else
                    {
                        MessageBoxData = new WinMessageBoxViewModel(player, cpu);
                    }
                };
                PassControlData.OkCommand = new SimpleCommand(async o =>
                {
                    PassControlData.Visibility = Visibility.Collapsed;
                    Othello.Pass();
                    var points = Update();
                    await AiPutAsync(points);
                });
                Othello.PassEvent += (othello, pass) =>
                {
                    if (pass == player)
                    {
                        PassControlData.Visibility = Visibility.Visible;
                    }
                };
                Initcpu(cpu, playercolor);
            }
        }