fn create_game(red: T::AccountId, blue: T::AccountId) -> T::Hash {
        // get a random hash as board id
        let board_id = Self::generate_random_hash(b"create", red.clone());

        // calculate plyer to start the first turn, with the first byte of the board_id random hash
        let next_player = if board_id.as_ref()[0] < 128 {
            PLAYER_1
        } else {
            PLAYER_2
        };

        // get current blocknumber
        let block_number = <frame_system::Pallet<T>>::block_number();

        // create a new empty game
        let board = BoardStruct {
            id: board_id,
            red: red.clone(),
            blue: blue.clone(),
            board: [[0u8; 6]; 7],
            last_turn: block_number,
            next_player,
            board_state: BoardState::Running,
        };

        // insert the new board into the storage
        <Boards<T>>::insert(board_id, board);

        // Add board to the players playing it.
        <PlayerBoard<T>>::insert(red, board_id);
        <PlayerBoard<T>>::insert(blue, board_id);

        // emit event for a new board creation
        // Emit an event.
        Self::deposit_event(Event::NewBoard(board_id));

        return board_id;
    }
/// Generate a new game between two players.
Generate a new game between two players.
Generate a new game between two players .
fn create_game(red: T::AccountId, blue: T::AccountId) -> T::Hash {
        // get a random hash as board id
        let board_id = Self::generate_random_hash(b"create", red.clone());
        // calculate plyer to start the first turn, with the first byte of the board_id random hash
        let next_player = if board_id.as_ref()[0] < 128 {
            PLAYER_1
        } else {
            PLAYER_2
        };
        // get current blocknumber
        let block_number = <frame_system::Pallet<T>>::block_number();
        // create a new empty game
        let board = BoardStruct {
            id: board_id,
            red: red.clone(),
            blue: blue.clone(),
            board: [[0u8; 6]; 7],
            last_turn: block_number,
            next_player,
            board_state: BoardState::Running,
        };
        // insert the new board into the storage
        <Boards<T>>::insert(board_id, board);
        // Add board to the players playing it.
        <PlayerBoard<T>>::insert(red, board_id);
        <PlayerBoard<T>>::insert(blue, board_id);
        // emit event for a new board creation
        // Emit an event.
        Self::deposit_event(Event::NewBoard(board_id));
        return board_id;
    }
fn create_game ( red : T :: AccountId , blue : T :: AccountId ) -> T :: Hash { // get a random hash as board id let board_id = Self :: generate_random_hash ( b" " , red . clone ( ) ) ; // calculate plyer to start the first turn, with the first byte of the board_id random hash let next_player = if board_id . as_ref ( ) [ 0 ] < 128 { PLAYER_1 } else { PLAYER_2 } ; // get current blocknumber let block_number = < frame_system :: Pallet < T > > :: block_number ( ) ; // create a new empty game let board = BoardStruct { id : board_id , red : red . clone ( ) , blue : blue . clone ( ) , board : [ [ 0u8 ; 6 ] ; 7 ] , last_turn : block_number , next_player , board_state : BoardState :: Running , } ; // insert the new board into the storage < Boards < T > > :: insert ( board_id , board ) ; // Add board to the players playing it. < PlayerBoard < T > > :: insert ( red , board_id ) ; < PlayerBoard < T > > :: insert ( blue , board_id ) ; // emit event for a new board creation // Emit an event. Self :: deposit_event ( Event :: NewBoard ( board_id ) ) ; return board_id ; }
Generate a new game between two players.
Generate a new game between two players .
red
T::AccountId
blue
T::AccountId
red
T::AccountId
blue
T::AccountId