Ejemplo n.º 1
0
// This function assumes that the frog is not in row 7 (the top row). A frog in row 7 is out
// of the game.
void move_frog_forward(void) {
	// Redraw the row the frog is currently on (this will remove the frog)
	redraw_row(frog_row);
	
	// Check whether this move will cause the frog to die or not
	frog_alive = frog_alive_at(frog_row+1, frog_column);
	
	// Move the frog position forward and show the frog. 
	// We do this whether the frog is alive or not. 
	frog_row++;
	redraw_frog();

	// If the frog has ended up successfully in row 7 - add it to the riverbank_status flag
	// also add 10 to the score
	if(frog_alive) {
	  if(frog_row == RIVERBANK_ROW) {
	    riverbank_status |= (1<<frog_column);
      add_to_score(10);
      halfway_awarded = 0;
	  } else if(frog_row == HALFWAY_ROW) {
	    // award halfway points if frog has reached the halfway point
	    // if the halfway mark hasn't already been awarded
      if(!halfway_awarded) {
        add_to_score(5);
        halfway_awarded = 1;
      }
	  } else {
	    // add 1 to the score
	    add_to_score(1);
	  }
	}
}
Ejemplo n.º 2
0
void test_move_sort_1(void)
{

    struct move_list mvl = {
        .moves = {0},
        .move_count = 0
    };

    uint32_t start_score = 3;
    uint32_t score_incr = 75;

    // create some dummy moves and scores
    for(int32_t i = 0; i < 20; i++) {
        // interested more in the score than squares or pieces

        uint32_t score = start_score + (uint32_t)(score_incr * i);
        mv_bitmap mv = MOVE(e5, e6, NO_PIECE, NO_PIECE, MFLAG_NONE);
        add_to_score(&mv, score);

        // add to move list
        mvl.moves[i] = mv;
        mvl.move_count++;
    }

    // sort to bring best score to top
    bring_best_move_to_top(0, &mvl);


    //print_move_list_details(&mvl);
    mv_bitmap top_mv = mvl.moves[0];
    assert_true(get_score(top_mv) == 1428);

}