Get rid of random blockgenerator in favor of a linear time one. Changed a sleep in ai to use gfx_sleep
This commit is contained in:
parent
05f2713179
commit
dc9adea7b5
3
src/ai.c
3
src/ai.c
|
@ -1,10 +1,11 @@
|
||||||
#include "ai.h"
|
#include "ai.h"
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
|
#include "gfx.h"
|
||||||
|
|
||||||
const char moves[] = {'w', 'a', 's', 'd'};
|
const char moves[] = {'w', 'a', 's', 'd'};
|
||||||
|
|
||||||
int ai_move(struct gamestate *g)
|
int ai_move(struct gamestate *g)
|
||||||
{
|
{
|
||||||
if (g->opts->interactive) usleep(50000);
|
if (g->opts->interactive) gfx_sleep(50);
|
||||||
return moves[rand() % 4];
|
return moves[rand() % 4];
|
||||||
}
|
}
|
||||||
|
|
25
src/engine.c
25
src/engine.c
|
@ -1,3 +1,4 @@
|
||||||
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "merge.h"
|
#include "merge.h"
|
||||||
|
@ -176,32 +177,28 @@ int gamestate_end_condition(struct gamestate *g)
|
||||||
void gamestate_new_block(struct gamestate *g)
|
void gamestate_new_block(struct gamestate *g)
|
||||||
{
|
{
|
||||||
/* Exit early if there are no spaces to place a block */
|
/* Exit early if there are no spaces to place a block */
|
||||||
if (g->blocks_in_play == g->gridsize) return;
|
if (g->blocks_in_play >= g->gridsize) return;
|
||||||
|
|
||||||
#ifdef FIX
|
|
||||||
int block_number = rand() % (g->gridsize - g->blocks_in_play);
|
int block_number = rand() % (g->gridsize - g->blocks_in_play);
|
||||||
|
|
||||||
int x, y, p = 0;
|
int x, y, p = 0;
|
||||||
for (y = 0; y < g->opts->grid_height; ++y) {
|
for (y = 0; y < g->opts->grid_height; ++y) {
|
||||||
for (x = 0; x < g->opts->grid_width; ++x) {
|
for (x = 0; x < g->opts->grid_width; ++x) {
|
||||||
|
if (!g->grid[x][y]) {
|
||||||
if (p == block_number) {
|
if (p == block_number) {
|
||||||
g->grid[x][y] = rand() & 1 ? 1 : 2;
|
g->grid[x][y] = rand() & 3 ? 1 : 2;
|
||||||
g->blocks_in_play += 1;
|
g->blocks_in_play += 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
if (!g->grid[x][y]) p++;
|
++p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (y == g->opts->grid_height - 1) y = 0;
|
/* This should never be reached; but just in case */
|
||||||
}
|
assert(0);
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Use rudimentary for now */
|
|
||||||
int x, y;
|
|
||||||
while (g->grid[x = rand() % g->opts->grid_width][y = rand() % g->opts->grid_height]);
|
|
||||||
g->grid[x][y] = rand() & 1 ? 1 : 2;
|
|
||||||
g->blocks_in_play += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This returns the number of digits in the base10 rep of n. The ceiling is
|
/* This returns the number of digits in the base10 rep of n. The ceiling is
|
||||||
|
|
Loading…
Reference in New Issue
Block a user