Exemplo n.º 1
0
        public int[] FindMovesInRow(Board state, int pos, int dirX, int dirY)
        {
            int        inRow = 1;
            List <int> moves = new List <int>();
            int        c     = state.board[pos];

            while (state.ColumnFromPosition(pos) - dirX >= 0 && state.ColumnFromPosition(pos) - dirX < state.width &&
                   state.RowFromPosition(pos) - dirY >= 0 && state.RowFromPosition(pos) - dirY < state.width &&
                   state.board[pos - dirX - (dirY * state.width)] == c)
            {
                pos = pos - dirX - (dirY * state.width);
            }
            if (state.ColumnFromPosition(pos) - dirX >= 0 && state.ColumnFromPosition(pos) - dirX < state.width &&
                state.RowFromPosition(pos) - dirY >= 0 && state.RowFromPosition(pos) - dirY < state.width &&
                state.board[pos - dirX - (dirY * state.width)] == 0)
            {
                moves.Add(pos - dirX - (dirY * state.width));
            }
            while (state.ColumnFromPosition(pos) + dirX >= 0 && state.ColumnFromPosition(pos) + dirX < state.width &&
                   state.RowFromPosition(pos) + dirY >= 0 && state.RowFromPosition(pos) + dirY < state.width &&
                   state.board[pos + dirX + (dirY * state.width)] == c)
            {
                pos = pos + dirX + (dirY * state.width);
                inRow++;
            }
            if (state.ColumnFromPosition(pos) + dirX >= 0 && state.ColumnFromPosition(pos) + dirX < state.width &&
                state.RowFromPosition(pos) + dirY >= 0 && state.RowFromPosition(pos) + dirY < state.width &&
                state.board[pos + dirX + (dirY * state.width)] == 0)
            {
                moves.Add(pos + dirX + (dirY * state.width));
            }
            if (inRow >= 3)
            {
                return(moves.ToArray());
            }
            else
            {
                return(new int[0]);
            }
        }
Exemplo n.º 2
0
        public int InRow(Board state, int pos, int dirX, int dirY)
        {
            int inRow  = 1;
            int blocks = 0;
            int c      = state.board[pos];

            while (state.ColumnFromPosition(pos) - dirX >= 0 && state.ColumnFromPosition(pos) - dirX < state.width &&
                   state.RowFromPosition(pos) - dirY >= 0 && state.RowFromPosition(pos) - dirY < state.width &&
                   state.board[pos - dirX - (dirY * state.width)] == c)
            {
                pos = pos - dirX - (dirY * state.width);
            }
            if (state.ColumnFromPosition(pos) - dirX < 0 || state.ColumnFromPosition(pos) - dirX >= state.width ||
                state.RowFromPosition(pos) - dirY < 0 || state.RowFromPosition(pos) - dirY >= state.width ||
                (state.board[pos - dirX - (dirY * state.width)] != c && state.board[pos - dirX - (dirY * state.width)] != 0))
            {
                blocks++;
            }
            while (state.ColumnFromPosition(pos) + dirX >= 0 && state.ColumnFromPosition(pos) + dirX < state.width &&
                   state.RowFromPosition(pos) + dirY >= 0 && state.RowFromPosition(pos) + dirY < state.width &&
                   state.board[pos + dirX + (dirY * state.width)] == c)
            {
                pos = pos + dirX + (dirY * state.width);
                inRow++;
            }
            if (state.ColumnFromPosition(pos) + dirX < 0 || state.ColumnFromPosition(pos) + dirX >= state.width ||
                state.RowFromPosition(pos) + dirY < 0 || state.RowFromPosition(pos) + dirY >= state.width ||
                (state.board[pos + dirX + (dirY * state.width)] != c && state.board[pos + dirX + (dirY * state.width)] != 0))
            {
                blocks++;
            }
            if (inRow >= 5)
            {
                return(10000);
            }
            else
            {
                if (inRow == 3)
                {
                    inRow = 7;
                }
                else if (inRow == 4)
                {
                    inRow = 12;
                }
                else if (inRow == 1)
                {
                    return(0);
                }
                if (blocks == 1)
                {
                    return(inRow / 2);
                }
                else if (blocks == 2)
                {
                    return(0);
                }
                else
                {
                    return(inRow);
                }
            }
        }