fn battle(
            board: &mut [[Option<Card>; 5]; 4],
            position: Position,
            neighbour_position: Position,
            direction: Direction,
        ) -> Option<FightResult> {
            let (y, x) = position;
            let (ny, nx) = neighbour_position;
            // determine the attacker
            let attacking_player: u8 = board[y][x].as_ref().unwrap().player;
            let neighbour = board[ny][nx].as_ref();

            // if neighbour exists, check it
            if let Some(neighbour) = neighbour {
                // fetch attacker
                let a = board[y][x].as_ref().unwrap();
                // fetch defender
                let d = neighbour;

                match direction {
                    Direction::Top => {
                        return Some(fight(
                            a.name,
                            d.name,
                            a.top,
                            d.bottom,
                            board,
                            attacking_player,
                            d.player,
                        ));
                    }
                    Direction::Right => {
                        return Some(fight(
                            a.name,
                            d.name,
                            a.right,
                            d.left,
                            board,
                            attacking_player,
                            d.player,
                        ));
                    }
                    Direction::Bottom => {
                        return Some(fight(
                            a.name,
                            d.name,
                            a.bottom,
                            d.top,
                            board,
                            attacking_player,
                            d.player,
                        ));
                    }
                    Direction::Left => {
                        return Some(fight(
                            a.name,
                            d.name,
                            a.left,
                            d.right,
                            board,
                            attacking_player,
                            d.player,
                        ));
                    }
                }
            }

            // if neighbour is empty or no fight was fought, return None
            return None;
        }
// handles battle with specified neighbour and returns the result
handles battle with specified neighbour and returns the result
handles battle with specified neighbour and returns the result
fn battle(
            board: &mut [[Option<Card>; 5]; 4],
            position: Position,
            neighbour_position: Position,
            direction: Direction,
        ) -> Option<FightResult> {
            let (y, x) = position;
            let (ny, nx) = neighbour_position;
            // determine the attacker
            let attacking_player: u8 = board[y][x].as_ref().unwrap().player;
            let neighbour = board[ny][nx].as_ref();
            // if neighbour exists, check it
            if let Some(neighbour) = neighbour {
                // fetch attacker
                let a = board[y][x].as_ref().unwrap();
                // fetch defender
                let d = neighbour;
                match direction {
                    Direction::Top => {
                        return Some(fight(
                            a.name,
                            d.name,
                            a.top,
                            d.bottom,
                            board,
                            attacking_player,
                            d.player,
                        ));
                    }
                    Direction::Right => {
                        return Some(fight(
                            a.name,
                            d.name,
                            a.right,
                            d.left,
                            board,
                            attacking_player,
                            d.player,
                        ));
                    }
                    Direction::Bottom => {
                        return Some(fight(
                            a.name,
                            d.name,
                            a.bottom,
                            d.top,
                            board,
                            attacking_player,
                            d.player,
                        ));
                    }
                    Direction::Left => {
                        return Some(fight(
                            a.name,
                            d.name,
                            a.left,
                            d.right,
                            board,
                            attacking_player,
                            d.player,
                        ));
                    }
                }
            }
            // if neighbour is empty or no fight was fought, return None
            return None;
        }
fn battle ( board : & mut [ [ Option < Card > ; 5 ] ; 4 ] , position : Position , neighbour_position : Position , direction : Direction , ) -> Option < FightResult > { let ( y , x ) = position ; let ( ny , nx ) = neighbour_position ; // determine the attacker let attacking_player : u8 = board [ y ] [ x ] . as_ref ( ) . unwrap ( ) . player ; let neighbour = board [ ny ] [ nx ] . as_ref ( ) ; // if neighbour exists, check it if let Some ( neighbour ) = neighbour { // fetch attacker let a = board [ y ] [ x ] . as_ref ( ) . unwrap ( ) ; // fetch defender let d = neighbour ; match direction { Direction :: Top => { return Some ( fight ( a . name , d . name , a . top , d . bottom , board , attacking_player , d . player , ) ) ; } Direction :: Right => { return Some ( fight ( a . name , d . name , a . right , d . left , board , attacking_player , d . player , ) ) ; } Direction :: Bottom => { return Some ( fight ( a . name , d . name , a . bottom , d . top , board , attacking_player , d . player , ) ) ; } Direction :: Left => { return Some ( fight ( a . name , d . name , a . left , d . right , board , attacking_player , d . player , ) ) ; } } } // if neighbour is empty or no fight was fought, return None return None ; }
handles battle with specified neighbour and returns the result
handles battle with specified neighbour and returns the result
board
&mut [[Option<Card>; 5]; 4]
position
Position
neighbour_position
Position
direction
Direction