commands/play.js
/**
     * @brief This function checks if the last 'move' caused the player to win
     *        the game. It checks the row, column and the diagonals if
     *        applicable.
     *
     * @param board game board array with all the moves
     * @param move location on the board corresponding to the last move
     *
     * @return object indicating if the player won ('status') and the 'row',
     *                'column' or 'diagonal' which has the winning symbols
     */
@brief This function checks if the last 'move' caused the player to win
the game. It checks the row, column and the diagonals if
applicable.

@param board game board array with all the moves
@param move location on the board corresponding to the last move


@brief This function checks if the last ' move ' caused the player to win the game . It checks the row column and the diagonals if applicable . @param board game board array with all the moves @param move location on the board corresponding to the last move
function hasWon(board, move) {
        let size = Math.sqrt(board.length);
        let row = Math.floor(move / size);
        let col = move % size;
        let val = board[move];
        function hasWonRow() {
            let i = 0;
            while (i < size) {
                if (board[size * row + i] !== val) {
                    return {status: false};
                }
                i = i + 1;
            }
            return {
                status: true,
                row: row
            };
        }
        function hasWonCol() {
            let i = 0;
            while (i < size) {
                if (board[size * i + col] !== val) {
                    return {status: false};
                }
                i = i + 1;
            }
            return {
                status: true,
                column: col
            };
        }
        function hasWonFwdDiagonal() {
            let i = 0;
            while (i < size) {
                if (board[size * i + i] !== val) {
                    return {status: false};
                }
                i = i + 1;
            }
            return {
                status: true,
                diaognal: 1
            };
        }
        function hasWonBwdDiagonal() {
            let i = 0;
            while (i < size) {
                if (board[size * i + (size - i - 1)] !== val) {
                    return {status: false};
                }
                i = i + 1;
            }
            return {
                status: true,
                diagonal: -1
            };
        }
        let win = hasWonRow();
        if (win.status === true) {
            return win;
        }
        win = hasWonCol();
        if (win.status === true) {
            return win;
        }
        if (row === col) {
            win = hasWonFwdDiagonal();
            if (win.status === true) {
                return win;
            }
        }
        if (row === size - col - 1) {
            win = hasWonBwdDiagonal();
            if (win.status === true) {
                return win;
            }
        }
        return {status: false};
    }
function hasWon ( board , move ) { let size = Math . sqrt ( board . length ) ; let row = Math . floor ( move / size ) ; let col = move % size ; let val = board [ move ] ; function hasWonRow ( ) { let i = 0 ; while ( i < size ) { if ( board [ size * row + i ] !== val ) { return { status : false } ; } i = i + 1 ; } return { status : true , row : row } ; } function hasWonCol ( ) { let i = 0 ; while ( i < size ) { if ( board [ size * i + col ] !== val ) { return { status : false } ; } i = i + 1 ; } return { status : true , column : col } ; } function hasWonFwdDiagonal ( ) { let i = 0 ; while ( i < size ) { if ( board [ size * i + i ] !== val ) { return { status : false } ; } i = i + 1 ; } return { status : true , diaognal : 1 } ; } function hasWonBwdDiagonal ( ) { let i = 0 ; while ( i < size ) { if ( board [ size * i + ( size - i - 1 ) ] !== val ) { return { status : false } ; } i = i + 1 ; } return { status : true , diagonal : - 1 } ; } let win = hasWonRow ( ) ; if ( win . status === true ) { return win ; } win = hasWonCol ( ) ; if ( win . status === true ) { return win ; } if ( row === col ) { win = hasWonFwdDiagonal ( ) ; if ( win . status === true ) { return win ; } } if ( row === size - col - 1 ) { win = hasWonBwdDiagonal ( ) ; if ( win . status === true ) { return win ; } } return { status : false } ; }
@brief This function checks if the last 'move' caused the player to win
        the game.
@brief This function checks if the last ' move ' caused the player to win the game .
/**
         * @brief This function checks if the last 'move' caused the player to
         *        win the game in the move's row.
         *
         * @return object indicating if the player won ('status') and the 'row',
         *                of the winning symbol
         */ /**
         * @brief This function checks if the last 'move' caused the player to
         *        win the game in the move's column.
         *
         * @return object indicating if the player won ('status') and the
         *                'column' of the winning symbol
         */ /**
         * @brief This function checks if the last 'move' caused the player to
         *        win the game in the fwd diagonal.
         *
         * @return object indicating if the player won ('status') and the
         *                'diagonal' of the winning symbol
         */ /**
         * @brief This function checks if the last 'move' caused the player to
         *        win the game in the backward diagonal.
         *
         * @return object indicating if the player won ('status') and the
         *                'diagonal' of the winning symbol
         */ // The last move did not cause the player to win the game.