Exemple #1
0
 public Space(int x, int y, State_Space state)
 {
     this.Row    = x;
     this.Column = y;
     this.State  = state;
     this.Moves  = new List <Space>();
 }
        public static State_Space[,] CloneBoard(State_Space[,] board)
        {
            var boardClone = new State_Space[Program.row_board_count, Program.column_board_count];

            for (int _x = 0; _x < Program.row_board_count; _x++)
            {
                for (int _y = 0; _y < Program.column_board_count; _y++)
                {
                    boardClone[_x, _y] = board[_x, _y];
                }
            }
            return(boardClone);
        }
        public static List <Space> SpaceOpponentBoard(State_Space[,] board, State_Space state_space_player)
        {
            var liste = new List <Space>();

            for (int _x = 0; _x < Program.row_board_count; _x++)
            {
                for (int _y = 0; _y < Program.column_board_count; _y++)
                {
                    if (board[_x, _y] == state_space_player)
                    {
                        liste.Add(new Space(_x, _y));
                    }
                }
            }
            return(liste);
        }
        public static Boolean IsVictory(State_Space[,] board, Type_Player type_player)
        {
            State_Space opponent = (type_player == Type_Player.One) ? State_Space.One
                                                                     : State_Space.Two;

            for (int _x = 0; _x < Program.row_board_count; _x++)
            {
                for (int _y = 0; _y < Program.column_board_count; _y++)
                {
                    if (board[_x, _y] == opponent)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
        public Form_Main(string name_1, string name_2) : this()
        {
            // -- Create players -- //
            Player_1 = new Player(name_1, true);
            Player_2 = new Player(name_2, false);
            // -- Update event -- //
            Player_1.PropertyChanged += Event_Property_Player_Change;
            Player_2.PropertyChanged += Event_Property_Player_Change;

            // -- Initialise var -- //
            Moves          = new List <Space>();
            MoveStack      = new List <Space>();
            Board          = new State_Space[RowCount, ColumnCount];
            isNotFirstplay = false;

            // -- Initialisation form -- //
            InitalisationForm();

            // -- Initialise current player -- //
            _currentPlayer = Type_Player.One;
        }
Exemple #6
0
 public void Simulation(State_Space[,] board, int rowLocation, int ColumnLocation, State_Space stape_space)
 {
     board[rowLocation, ColumnLocation] = stape_space;
 }
Exemple #7
0
        public static List <Space> Enable_Space(State_Space[,] Board, Space space, Type_Player type_player)
        {
            List <Space> list     = new List <Space>();
            State_Space  my_state = (type_player == Type_Player.One) ? State_Space.One
                                                                    : State_Space.Two;
            Boolean have_opponent = false;

            for (int passage = 1; passage <= 4; passage++)
            {
                // -- Var
                int row = space.Row, row_second = space.Row,
                    column = space.Column, column_second = space.Column;

                // -- Update var with passage
                switch (passage)
                {
                case 1:
                    row        = space.Row - 1;
                    row_second = space.Row - 2;
                    break;

                case 2:
                    row        = space.Row + 1;
                    row_second = space.Row + 2;
                    break;

                case 3:
                    column        = space.Column - 1;
                    column_second = space.Column - 2;
                    break;

                default:
                    column        = space.Column + 1;
                    column_second = space.Column + 2;
                    break;
                }

                // x-1, x+1, y-1, y+1
                try
                {
                    if (Board[row, column] != my_state)
                    {
                        // -- Space to mive -- //
                        if (Board[row, column] == State_Space.None)
                        {
                            // -- Add
                            list.Add(new Space(row, column, Board[row, column]));
                        }
                        // -- Space to win -- //
                        else if (Board[row_second, column_second] == State_Space.None)
                        {
                            // -- Add
                            list.Add(new Space(row, column, Board[row, column]));
                            // -- Add second
                            list.Add(new Space(row_second, column_second, Board[row_second, column_second]));
                            // -- Update opponent -- //
                            have_opponent = true;
                        }
                    }
                }
                catch { }
            }

            if (have_opponent)
            {
                // -- remove -- //
                list.RemoveAll(l => (Math.Abs(l.Row - space.Row) == 1 || Math.Abs(l.Column - space.Column) == 1) &&
                               l.State == State_Space.None);
            }

            return(list);
        }