public OthelloBoard SetPieceCreatedBoard(int i, int j, int player)
        {
            var newOthello = new OthelloBoard(this);

            newOthello.Board[i, j] = player;
            FlipPieces(i, j, player, newOthello);

            newOthello.Flips.Clear();
            return(newOthello);
        }
 public OthelloGui(OthelloBoard othelloBoard)
 {
     InitializeComponent();
     _othelloBoard       = othelloBoard;
     _n                  = _othelloBoard.N;
     _m                  = _othelloBoard.M;
     _availableMoves     = _othelloBoard.AvailableMoves(_othelloBoard.Turn);
     turnBox.BackColor   = _othelloBoard.Turn == 1 ? Color.Black : Color.White;
     _minimax            = new Minimax(3, false);
     aiPlayTimer.Enabled = true;
 }
 private OthelloBoard(OthelloBoard othelloBoard)
 {
     Board = new int[othelloBoard.N, othelloBoard.M];
     M     = othelloBoard.M;
     N     = othelloBoard.N;
     Turn  = othelloBoard.Turn;
     Flips = new Dictionary <Tuple <int, int>, List <Tuple <int, int> > >(othelloBoard.Flips);
     Array.Copy(othelloBoard.Board, Board, othelloBoard.N * othelloBoard.M);
     Player1Pos = new List <Tuple <int, int> >(othelloBoard.Player1Pos);
     Player2Pos = new List <Tuple <int, int> >(othelloBoard.Player2Pos);
 }
        private void UpdatePiecePos(Tuple <int, int> pair, int player, OthelloBoard othello)
        {
            var removeFrom = player == 1 ? othello.Player2Pos : othello.Player1Pos;
            var addTo      = player == 1 ? othello.Player1Pos : othello.Player2Pos;

            if (!addTo.Contains(pair))
            {
                addTo.Add(pair);
            }
            removeFrom.Remove(pair);
        }
        private void FlipPieces(int i, int j, int player, OthelloBoard othello)
        {
            var piecesToFlip = Flips[new Tuple <int, int>(i, j)];

            UpdatePiecePos(new Tuple <int, int>(i, j), player, othello);

            foreach (var pair in piecesToFlip)
            {
                othello.Board[pair.Item1, pair.Item2] = player;
                UpdatePiecePos(pair, player, othello);
            }
        }