Skip to content
Snippets Groups Projects
Commit 45a24c4d authored by dario.genga's avatar dario.genga
Browse files

Add random play

parent 4f312d72
No related branches found
No related tags found
No related merge requests found
...@@ -5,31 +5,20 @@ ...@@ -5,31 +5,20 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h>
#include "puissance.h" #include "puissance.h"
int main() { int main() {
srand(time(NULL));
puissance game; puissance game;
game_init(&game, RAND_AI, DEFAULT_ROW, DEFAULT_COL); game_init(&game, RAND_AI, DEFAULT_ROW, DEFAULT_COL);
print_game(game); print_game(game);
random_play(&game);
print_game(game); print_game(game);
manual_play(&game, 0); random_play(&game);
print_game(game); print_game(game);
manual_play(&game, 4); random_play(&game);
print_game(game);
manual_play(&game, 0);
print_game(game);
manual_play(&game, -1);
print_game(game);
manual_play(&game, 9);
print_game(game);
manual_play(&game, 0);
manual_play(&game, 0);
manual_play(&game, 0);
manual_play(&game, 0);
print_game(game);
manual_play(&game, 0);
manual_play(&game, 1);
print_game(game); print_game(game);
game_destroy(&game); game_destroy(&game);
......
...@@ -153,9 +153,14 @@ bool manual_play(puissance *p, int selected_col_index) { ...@@ -153,9 +153,14 @@ bool manual_play(puissance *p, int selected_col_index) {
} }
bool random_play(puissance *p) { bool random_play(puissance *p) {
bool valid_action = true; int max = p->col - 1;
int min = 0;
int random_index = -1;
do {
random_index = rand() % (max - min + 1) + min;
} while(manual_play(p, random_index) == false);
return valid_action; return true;
} }
bool smart_play(puissance *p) { bool smart_play(puissance *p) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment