fn handle_result(
            result: FightResult,
            same: u8,
            position: Position,
            neighbour_position: Position,
            board: &mut [[Option<Card>; 5]; 4],
            combo: bool,
            direction: Direction,
            pierce: bool,
        ) {
            // println!(
            //     "Handling a {:?} @ {}, {} vs {}, {} towards {:?} with same_count = {}, combo = {}, pierce = {}",
            //     result,
            //     position.0 + 1,
            //     position.1 + 1,
            //     neighbour_position.0 + 1,
            //     neighbour_position.1 + 1,
            //     direction,
            //     same,
            //     combo,
            //     pierce
            // );
            match result {
                FightResult::Win => {
                    // capture neighbour when the battle is won
                    capture_event(neighbour_position, position, board, combo);

                    let (y, x) = position;
                    let (ny, nx) = neighbour_position;

                    // Lancer has pierce ability which attacks fallen neighbour's neighbour
                    if !pierce && board[y][x].as_ref().unwrap().name == Unit::Lancer {
                        // fetch defender (card to be pierced)
                        let def = Card::get_neighbour(board, direction, ny, nx, Unit::Lancer);

                        // if there is a card to pierce
                        if let Some(d) = def {
                            // swap lancer with it's defeated neighbour
                            let temp_card = board[ny][nx].take();
                            board[ny][nx] = board[y][x].take();

                            // commence battle at the neighbour's position
                            let battle_result = battle(board, neighbour_position, d, direction);

                            // check if there was a battle
                            if battle_result.is_some() {
                                // handle the result
                                handle_result(
                                    battle_result.unwrap(),
                                    0,
                                    neighbour_position,
                                    d,
                                    board,
                                    combo,
                                    direction,
                                    true,
                                );
                            }

                            // now put the cards back into their original positions
                            board[y][x] = board[ny][nx].take();
                            board[ny][nx] = temp_card;
                        }
                    }
                }
                FightResult::Tie => {
                    // if more than one neighbours have same values, it's a valid capture
                    if same > 1 {
                        // a same capture starts a Same Chain
                        capture_event(neighbour_position, position, board, true);
                    }
                }
                FightResult::Lose => {}
            }
        }
// handles the result of the battle triggering capture event accordingly
handles the result of the battle triggering capture event accordingly
handles the result of the battle triggering capture event accordingly
fn handle_result(
            result: FightResult,
            same: u8,
            position: Position,
            neighbour_position: Position,
            board: &mut [[Option<Card>; 5]; 4],
            combo: bool,
            direction: Direction,
            pierce: bool,
        ) {
            // println!(
            //     "Handling a {:?} @ {}, {} vs {}, {} towards {:?} with same_count = {}, combo = {}, pierce = {}",
            //     result,
            //     position.0 + 1,
            //     position.1 + 1,
            //     neighbour_position.0 + 1,
            //     neighbour_position.1 + 1,
            //     direction,
            //     same,
            //     combo,
            //     pierce
            // );
            match result {
                FightResult::Win => {
                    // capture neighbour when the battle is won
                    capture_event(neighbour_position, position, board, combo);
                    let (y, x) = position;
                    let (ny, nx) = neighbour_position;
                    // Lancer has pierce ability which attacks fallen neighbour's neighbour
                    if !pierce && board[y][x].as_ref().unwrap().name == Unit::Lancer {
                        // fetch defender (card to be pierced)
                        let def = Card::get_neighbour(board, direction, ny, nx, Unit::Lancer);
                        // if there is a card to pierce
                        if let Some(d) = def {
                            // swap lancer with it's defeated neighbour
                            let temp_card = board[ny][nx].take();
                            board[ny][nx] = board[y][x].take();
                            // commence battle at the neighbour's position
                            let battle_result = battle(board, neighbour_position, d, direction);
                            // check if there was a battle
                            if battle_result.is_some() {
                                // handle the result
                                handle_result(
                                    battle_result.unwrap(),
                                    0,
                                    neighbour_position,
                                    d,
                                    board,
                                    combo,
                                    direction,
                                    true,
                                );
                            }
                            // now put the cards back into their original positions
                            board[y][x] = board[ny][nx].take();
                            board[ny][nx] = temp_card;
                        }
                    }
                }
                FightResult::Tie => {
                    // if more than one neighbours have same values, it's a valid capture
                    if same > 1 {
                        // a same capture starts a Same Chain
                        capture_event(neighbour_position, position, board, true);
                    }
                }
                FightResult::Lose => {}
            }
        }
fn handle_result ( result : FightResult , same : u8 , position : Position , neighbour_position : Position , board : & mut [ [ Option < Card > ; 5 ] ; 4 ] , combo : bool , direction : Direction , pierce : bool , ) { // println!( //     "Handling a {:?} @ {}, {} vs {}, {} towards {:?} with same_count = {}, combo = {}, pierce = {}", //     result, //     position.0 + 1, //     position.1 + 1, //     neighbour_position.0 + 1, //     neighbour_position.1 + 1, //     direction, //     same, //     combo, //     pierce // ); match result { FightResult :: Win => { // capture neighbour when the battle is won capture_event ( neighbour_position , position , board , combo ) ; let ( y , x ) = position ; let ( ny , nx ) = neighbour_position ; // Lancer has pierce ability which attacks fallen neighbour's neighbour if ! pierce && board [ y ] [ x ] . as_ref ( ) . unwrap ( ) . name == Unit :: Lancer { // fetch defender (card to be pierced) let def = Card :: get_neighbour ( board , direction , ny , nx , Unit :: Lancer ) ; // if there is a card to pierce if let Some ( d ) = def { // swap lancer with it's defeated neighbour let temp_card = board [ ny ] [ nx ] . take ( ) ; board [ ny ] [ nx ] = board [ y ] [ x ] . take ( ) ; // commence battle at the neighbour's position let battle_result = battle ( board , neighbour_position , d , direction ) ; // check if there was a battle if battle_result . is_some ( ) { // handle the result handle_result ( battle_result . unwrap ( ) , 0 , neighbour_position , d , board , combo , direction , true , ) ; } // now put the cards back into their original positions board [ y ] [ x ] = board [ ny ] [ nx ] . take ( ) ; board [ ny ] [ nx ] = temp_card ; } } } FightResult :: Tie => { // if more than one neighbours have same values, it's a valid capture if same > 1 { // a same capture starts a Same Chain capture_event ( neighbour_position , position , board , true ) ; } } FightResult :: Lose => { } } }
handles the result of the battle triggering capture event accordingly
handles the result of the battle triggering capture event accordingly
result
FightResult
same
u8
position
Position
neighbour_position
Position
board
&mut [[Option<Card>; 5]; 4]
combo
bool
direction
Direction
pierce
bool