From 55bfff7cf6541caac172b43186cf14405185b14d Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Sat, 13 Apr 2019 12:40:52 -0400 Subject: fix curses on linux --- core/include/input.h | 18 +- core/include/matrix.h | 30 +-- core/include/test.h | 16 +- core/include/types.h | 56 +++--- core/meson.build | 24 +-- core/src/input.c | 102 +++++----- core/src/matrix.c | 538 +++++++++++++++++++++++++------------------------- core/src/test.c | 144 +++++++------- 8 files changed, 464 insertions(+), 464 deletions(-) (limited to 'core') diff --git a/core/include/input.h b/core/include/input.h index 1199991..3cfa947 100644 --- a/core/include/input.h +++ b/core/include/input.h @@ -1,9 +1,9 @@ -#pragma once - -#include -#include - -struct cetris_game; - -bool handle_inputs(struct cetris_game* g); -void clear_held_key(struct cetris_game* g); +#pragma once + +#include +#include + +struct cetris_game; + +bool handle_inputs(struct cetris_game* g); +void clear_held_key(struct cetris_game* g); diff --git a/core/include/matrix.h b/core/include/matrix.h index 5b6a74c..658906c 100644 --- a/core/include/matrix.h +++ b/core/include/matrix.h @@ -1,15 +1,15 @@ -#pragma once - -#include - -#include "types.h" -#include "cetris.h" - -extern const piece_matrix default_matrices[7]; -extern const vec2 basic_movements[4]; - -void move_current(struct cetris_game* g, vec2 offset); -void overlay_current_matrix(struct cetris_game* g); -void hard_drop(struct cetris_game* g); -void rotate_matrix(struct cetris_game* g, bool clockwise); -i8 check_new_matrix(struct cetris_game* g, piece_matrix m); +#pragma once + +#include + +#include "types.h" +#include "cetris.h" + +extern const piece_matrix default_matrices[7]; +extern const vec2 basic_movements[4]; + +void move_current(struct cetris_game* g, vec2 offset); +void overlay_current_matrix(struct cetris_game* g); +void hard_drop(struct cetris_game* g); +void rotate_matrix(struct cetris_game* g, bool clockwise); +i8 check_new_matrix(struct cetris_game* g, piece_matrix m); diff --git a/core/include/test.h b/core/include/test.h index 04fd09a..d700627 100644 --- a/core/include/test.h +++ b/core/include/test.h @@ -1,8 +1,8 @@ -struct cetris_game; - -enum tests { - TSPIN, - TSPIN_NO_LINES -}; - -void apply_test_board(struct cetris_game* g, enum tests t); +struct cetris_game; + +enum tests { + TSPIN, + TSPIN_NO_LINES +}; + +void apply_test_board(struct cetris_game* g, enum tests t); diff --git a/core/include/types.h b/core/include/types.h index a20773b..0431de1 100644 --- a/core/include/types.h +++ b/core/include/types.h @@ -1,28 +1,28 @@ -#pragma once - -#include - -#define u8 uint8_t -#define u16 uint16_t -#define u32 uint32_t -#define u64 uint64_t -#define i8 int8_t -#define i16 int16_t -#define i32 int32_t -#define i64 int64_t - -typedef struct { - i8 x; - i8 y; -} vec2; - -typedef u8 piece_matrix[4][4]; - -typedef enum { - DOWN = 1, - RIGHT = 2, - LEFT = 3, - ROTATE_CCW = 4, - ROTATE_CW = 5, - HARD_DROP = 6 -} input_t; +#pragma once + +#include + +#define u8 uint8_t +#define u16 uint16_t +#define u32 uint32_t +#define u64 uint64_t +#define i8 int8_t +#define i16 int16_t +#define i32 int32_t +#define i64 int64_t + +typedef struct { + i8 x; + i8 y; +} vec2; + +typedef u8 piece_matrix[4][4]; + +typedef enum { + DOWN = 1, + RIGHT = 2, + LEFT = 3, + ROTATE_CCW = 4, + ROTATE_CW = 5, + HARD_DROP = 6 +} input_t; diff --git a/core/meson.build b/core/meson.build index 1832f26..c1134c6 100644 --- a/core/meson.build +++ b/core/meson.build @@ -1,12 +1,12 @@ -src = ['src/cetris.c', 'src/input.c', 'src/matrix.c'] - -if get_option('debug') == true - src += 'src/test.c' -endif - -cetris_lib = static_library('cetris', src, - include_directories: cetris_inc, - install: false) - -cetris = declare_dependency(include_directories: cetris_inc, - link_with: cetris_lib) +src = ['src/cetris.c', 'src/input.c', 'src/matrix.c'] + +if get_option('debug') == true + src += 'src/test.c' +endif + +cetris_lib = static_library('cetris', src, + include_directories: cetris_inc, + install: false) + +cetris = declare_dependency(include_directories: cetris_inc, + link_with: cetris_lib) diff --git a/core/src/input.c b/core/src/input.c index 08d6219..edcd450 100644 --- a/core/src/input.c +++ b/core/src/input.c @@ -1,51 +1,51 @@ -#include - -#include "input.h" - -#include "types.h" -#include "matrix.h" -#include "cetris.h" - -bool handle_inputs(struct cetris_game* g) { - if ((g->held_moves[RIGHT] || g->held_moves[LEFT]) && !g->das_move_tick) { - if (g->das_repeat == 0) { - g->das_move_tick = g->tick + CETRIS_DAS_DELAY; - } else if (g->das_repeat > 0) { - g->das_move_tick = g->tick + CETRIS_DAS_PERIOD; - } - } - - if (g->held_moves[DOWN] && !g->down_move_tick) { - g->down_move_tick = g->tick + CETRIS_DROP_PERIOD; - } - - bool did_move = false; - if (g->das_move_tick && g->tick >= g->das_move_tick) { - if (g->held_moves[RIGHT]) { - if (g->prev_das_move == RIGHT || g->das_repeat == 0) g->das_repeat++; - else g->das_repeat = 0; - move_current(g, basic_movements[RIGHT]); - g->prev_das_move = RIGHT; - } - - if (g->held_moves[LEFT]) { - if (g->prev_das_move == LEFT || g->das_repeat == 0) g->das_repeat++; - else g->das_repeat = 0; - move_current(g, basic_movements[LEFT]); - g->prev_das_move = LEFT; - } - - g->das_move_tick = 0; - did_move = true; - } - - if (g->down_move_tick && g->tick >= g->down_move_tick) { - if (g->held_moves[DOWN]) { - move_current(g, basic_movements[DOWN]); - } - - g->down_move_tick = 0; - did_move = true; - } - return did_move; -} +#include + +#include "input.h" + +#include "types.h" +#include "matrix.h" +#include "cetris.h" + +bool handle_inputs(struct cetris_game* g) { + if ((g->held_moves[RIGHT] || g->held_moves[LEFT]) && !g->das_move_tick) { + if (g->das_repeat == 0) { + g->das_move_tick = g->tick + CETRIS_DAS_DELAY; + } else if (g->das_repeat > 0) { + g->das_move_tick = g->tick + CETRIS_DAS_PERIOD; + } + } + + if (g->held_moves[DOWN] && !g->down_move_tick) { + g->down_move_tick = g->tick + CETRIS_DROP_PERIOD; + } + + bool did_move = false; + if (g->das_move_tick && g->tick >= g->das_move_tick) { + if (g->held_moves[RIGHT]) { + if (g->prev_das_move == RIGHT || g->das_repeat == 0) g->das_repeat++; + else g->das_repeat = 0; + move_current(g, basic_movements[RIGHT]); + g->prev_das_move = RIGHT; + } + + if (g->held_moves[LEFT]) { + if (g->prev_das_move == LEFT || g->das_repeat == 0) g->das_repeat++; + else g->das_repeat = 0; + move_current(g, basic_movements[LEFT]); + g->prev_das_move = LEFT; + } + + g->das_move_tick = 0; + did_move = true; + } + + if (g->down_move_tick && g->tick >= g->down_move_tick) { + if (g->held_moves[DOWN]) { + move_current(g, basic_movements[DOWN]); + } + + g->down_move_tick = 0; + did_move = true; + } + return did_move; +} diff --git a/core/src/matrix.c b/core/src/matrix.c index 204d920..265fe05 100644 --- a/core/src/matrix.c +++ b/core/src/matrix.c @@ -1,269 +1,269 @@ -#include - -#include "matrix.h" -#include "types.h" -#include "cetris.h" - -/* SRS WALL KICK VALUES */ - -// https://tetris.wiki/SRS -static const vec2 srs_wall_kicks[8][5] = { - { {0, 0}, {-1, 0}, {-1,1}, {0,-2}, {-1,-2} }, // 0->R - { {0, 0}, {1, 0}, {1,-1}, {0,2}, {1,2} }, // R->0 - { {0, 0}, {1, 0}, {1,-1}, {0,2}, {1,2} }, // R->2 - { {0, 0}, {-1, 0}, {-1,1}, {0,-2}, {-1,-2} }, // 2->R - { {0, 0}, {1, 0}, {1,1}, {0,-2}, {1,-2} }, // 2->L - { {0, 0}, {-1, 0}, {-1,-1}, {0,2}, {-1,2} }, // L->2 - { {0, 0}, {-1, 0}, {-1,-1}, {0,2}, {-1,2} }, // L->0 - { {0, 0}, {1, 0}, {1,1}, {0,-2}, {1,-2} } // 0->L -}; - -static const vec2 srs_wall_kicks_i[8][5] = { - { {0, 0}, {-2, 0}, {1, 0}, {-2,-1}, {1,2} }, // 0->R - { {0, 0}, {2, 0}, {-1, 0}, {2,1}, {-1,-2} }, // R->0 - { {0, 0}, {-1, 0}, {2, 0}, {-1,2}, {2,-1} }, // R->2 - { {0, 0}, {1, 0}, {-2, 0}, {1,-2}, {-2,1} }, // 2->R - { {0, 0}, {2, 0}, {-1, 0}, {2,1}, {-1,-2} }, // 2->L - { {0, 0}, {-2, 0}, {1, 0}, {-2,-1}, {1,2} }, // L->2 - { {0, 0}, {1, 0}, {-2, 0}, {1,-2}, {-2,1} }, // L->0 - { {0, 0}, {-1, 0}, {2, 0}, {-1,2}, {2,-1} } // 0->L -}; - -/* DEFAULT MATRIX FOR EACH POSSIBLE TETRIMINO */ - -const piece_matrix default_matrices[7] = { - { - { 0, 0, 0, 0 }, - { 0, 1, 1, 0 }, - { 0, 1, 1, 0 }, - { 0, 0, 0, 0 } - }, - - { - { 0, 0, 0, 0 }, - { 1, 1, 1, 1 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 } - }, - - { - { 0, 0, 0, 0 }, - { 0, 1, 1, 0 }, - { 1, 1, 0, 0 }, - { 0, 0, 0, 0 } - }, - - { - { 0, 0, 0, 0 }, - { 1, 1, 0, 0 }, - { 0, 1, 1, 0 }, - { 0, 0, 0, 0 } - }, - - { - { 0, 0, 0, 0 }, - { 0, 0, 1, 0 }, - { 1, 1, 1, 0 }, - { 0, 0, 0, 0 } - }, - - { - { 0, 0, 0, 0 }, - { 1, 0, 0, 0 }, - { 1, 1, 1, 0 }, - { 0, 0, 0, 0 } - }, - - { - { 0, 0, 0, 0 }, - { 0, 1, 0, 0 }, - { 1, 1, 1, 0 }, - { 0, 0, 0, 0 } - } -}; - -/* MATRIX MODIFICATION */ - -const vec2 basic_movements[4] = { - {0, 0}, {0, 1}, {1, 0}, {-1, 0} // NONE, DOWN, RIGHT, LEFT -}; - -void move_current(struct cetris_game* g, vec2 offset) { - if (g->game_over) return; - - g->current.pos.y += offset.y; - g->current.pos.x += offset.x; - - int32_t check = check_new_matrix(g, g->current.m); - if (check <= 0) { - g->current.pos.y -= offset.y; - g->current.pos.x -= offset.x; - - if (check == -1 && g->current.lock_tick == 0) { - g->current.lock_tick = g->tick + 30; - } - } - - wipe_board(g); -} - -void overlay_current_matrix(struct cetris_game* g) { - for (uint32_t y = 0; y < 4; y++) { - for (uint32_t x = 0; x < 4; x++) { - vec2 r = (vec2){x + g->current.pos.x, y + g->current.pos.y}; - if (g->current.m[y][x]) { - g->board[r.x][r.y].occupied = 1; - g->board[r.x][r.y].c = g->current.c; - } - } - } -} - -void hard_drop(struct cetris_game* g) { - if (g->game_over) return; - - bool drop = false; - u8 drop_count = 0; - while (!drop) { - g->current.pos.y++; - drop_count++; - i8 check = check_new_matrix(g, g->current.m); - if (check <= 0) { - g->current.pos.y--; - drop_count--; - drop = true; - } - } - - g->score += 2 * drop_count; // 2 score for each harddrop cell - - wipe_board(g); - next_piece(g); -} - -void rotate_matrix(struct cetris_game* g, bool clockwise) { - if (g->game_over) return; - if (g->current.t == O) return; - - rstate next; - u8 wall_kick = 0; - switch (g->current.r) { - case INIT: - if (clockwise) { - next = ONCE_RIGHT; - wall_kick = 0; - } else { - next = ONCE_LEFT; - wall_kick = 7; - } break; - case ONCE_RIGHT: - if (clockwise) { - next = TWICE; - wall_kick = 2; - } else { - next = INIT; - wall_kick = 1; - } break; - case ONCE_LEFT: - if (clockwise) { - next = INIT; - wall_kick = 6; - } else { - next = TWICE; - wall_kick = 5; - } break; - case TWICE: - if (clockwise) { - next = ONCE_LEFT; - wall_kick = 4; - } else { - next = ONCE_RIGHT; - wall_kick = 3; - } break; - } - - piece_matrix m; - memset(m, 0, sizeof(piece_matrix)); - - for (u8 x = 0; x < 4; x++) { - for (u8 y = 0; y < 4; y++) { - if (g->current.m[y][x]) { - u8 new_x = (clockwise) ? 1 - (y - 2) : 1 + (y - 2); - u8 new_y = (clockwise) ? 2 + (x - 1) : 2 - (x - 1); - - if (g->current.t == I) { - if (clockwise) new_y--; - else new_x++; - } - - m[new_y][new_x] = 1; - } - } - } - - vec2 kick; - bool set_current = false; - bool did_kick = false; - for (u8 i = 0; i < 5; i++) { - if (g->current.t == I) { - kick = srs_wall_kicks_i[wall_kick][i]; - } else { - kick = srs_wall_kicks[wall_kick][i]; - } - g->current.pos.x += kick.x; - g->current.pos.y += kick.y; - if (check_new_matrix(g, m) > 0) { - set_current = true; - if (i > 0) did_kick = true; - break; - } else { - g->current.pos.x -= kick.x; - g->current.pos.y -= kick.y; - } - } - - if (set_current) { - /* check for tspin */ - if (g->current.t == T) { - u8 did_tspin = 1; - for (u8 i = 0; i < 4; i++) { - g->current.pos.x += basic_movements[i].x; - g->current.pos.y += basic_movements[i].y; - - if (check_new_matrix(g, m) == 1) - did_tspin = 0; - - g->current.pos.x -= basic_movements[i].x; - g->current.pos.y -= basic_movements[i].y; - } - - if (did_tspin) { - if (did_kick) g->mini_tspin = 1; - else g->tspin = 1; - } - } - - g->current.r = next; - memcpy(g->current.m, m, sizeof(piece_matrix)); - wipe_board(g); - } -} - -i8 check_new_matrix(struct cetris_game* g, piece_matrix m) { - for (u8 x = 0; x < 4; x++) { - for (u8 y = 0; y < 4; y++) { - vec2 r = (vec2){g->current.pos.x + x, g->current.pos.y + y}; - if (m[y][x]) { - if (r.x > CETRIS_BOARD_X - 1 || r.x < 0) - return 0; - - if (r.y > CETRIS_BOARD_Y - 1 || r.y < 0) - return -1; - - if (g->board[r.x][r.y].occupied && g->board[r.x][r.y].constant) - return -1; - } - } - } - return 1; -} +#include + +#include "matrix.h" +#include "types.h" +#include "cetris.h" + +/* SRS WALL KICK VALUES */ + +// https://tetris.wiki/SRS +static const vec2 srs_wall_kicks[8][5] = { + { {0, 0}, {-1, 0}, {-1,1}, {0,-2}, {-1,-2} }, // 0->R + { {0, 0}, {1, 0}, {1,-1}, {0,2}, {1,2} }, // R->0 + { {0, 0}, {1, 0}, {1,-1}, {0,2}, {1,2} }, // R->2 + { {0, 0}, {-1, 0}, {-1,1}, {0,-2}, {-1,-2} }, // 2->R + { {0, 0}, {1, 0}, {1,1}, {0,-2}, {1,-2} }, // 2->L + { {0, 0}, {-1, 0}, {-1,-1}, {0,2}, {-1,2} }, // L->2 + { {0, 0}, {-1, 0}, {-1,-1}, {0,2}, {-1,2} }, // L->0 + { {0, 0}, {1, 0}, {1,1}, {0,-2}, {1,-2} } // 0->L +}; + +static const vec2 srs_wall_kicks_i[8][5] = { + { {0, 0}, {-2, 0}, {1, 0}, {-2,-1}, {1,2} }, // 0->R + { {0, 0}, {2, 0}, {-1, 0}, {2,1}, {-1,-2} }, // R->0 + { {0, 0}, {-1, 0}, {2, 0}, {-1,2}, {2,-1} }, // R->2 + { {0, 0}, {1, 0}, {-2, 0}, {1,-2}, {-2,1} }, // 2->R + { {0, 0}, {2, 0}, {-1, 0}, {2,1}, {-1,-2} }, // 2->L + { {0, 0}, {-2, 0}, {1, 0}, {-2,-1}, {1,2} }, // L->2 + { {0, 0}, {1, 0}, {-2, 0}, {1,-2}, {-2,1} }, // L->0 + { {0, 0}, {-1, 0}, {2, 0}, {-1,2}, {2,-1} } // 0->L +}; + +/* DEFAULT MATRIX FOR EACH POSSIBLE TETRIMINO */ + +const piece_matrix default_matrices[7] = { + { + { 0, 0, 0, 0 }, + { 0, 1, 1, 0 }, + { 0, 1, 1, 0 }, + { 0, 0, 0, 0 } + }, + + { + { 0, 0, 0, 0 }, + { 1, 1, 1, 1 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 } + }, + + { + { 0, 0, 0, 0 }, + { 0, 1, 1, 0 }, + { 1, 1, 0, 0 }, + { 0, 0, 0, 0 } + }, + + { + { 0, 0, 0, 0 }, + { 1, 1, 0, 0 }, + { 0, 1, 1, 0 }, + { 0, 0, 0, 0 } + }, + + { + { 0, 0, 0, 0 }, + { 0, 0, 1, 0 }, + { 1, 1, 1, 0 }, + { 0, 0, 0, 0 } + }, + + { + { 0, 0, 0, 0 }, + { 1, 0, 0, 0 }, + { 1, 1, 1, 0 }, + { 0, 0, 0, 0 } + }, + + { + { 0, 0, 0, 0 }, + { 0, 1, 0, 0 }, + { 1, 1, 1, 0 }, + { 0, 0, 0, 0 } + } +}; + +/* MATRIX MODIFICATION */ + +const vec2 basic_movements[4] = { + {0, 0}, {0, 1}, {1, 0}, {-1, 0} // NONE, DOWN, RIGHT, LEFT +}; + +void move_current(struct cetris_game* g, vec2 offset) { + if (g->game_over) return; + + g->current.pos.y += offset.y; + g->current.pos.x += offset.x; + + int32_t check = check_new_matrix(g, g->current.m); + if (check <= 0) { + g->current.pos.y -= offset.y; + g->current.pos.x -= offset.x; + + if (check == -1 && g->current.lock_tick == 0) { + g->current.lock_tick = g->tick + 30; + } + } + + wipe_board(g); +} + +void overlay_current_matrix(struct cetris_game* g) { + for (uint32_t y = 0; y < 4; y++) { + for (uint32_t x = 0; x < 4; x++) { + vec2 r = (vec2){x + g->current.pos.x, y + g->current.pos.y}; + if (g->current.m[y][x]) { + g->board[r.x][r.y].occupied = 1; + g->board[r.x][r.y].c = g->current.c; + } + } + } +} + +void hard_drop(struct cetris_game* g) { + if (g->game_over) return; + + bool drop = false; + u8 drop_count = 0; + while (!drop) { + g->current.pos.y++; + drop_count++; + i8 check = check_new_matrix(g, g->current.m); + if (check <= 0) { + g->current.pos.y--; + drop_count--; + drop = true; + } + } + + g->score += 2 * drop_count; // 2 score for each harddrop cell + + wipe_board(g); + next_piece(g); +} + +void rotate_matrix(struct cetris_game* g, bool clockwise) { + if (g->game_over) return; + if (g->current.t == O) return; + + rstate next; + u8 wall_kick = 0; + switch (g->current.r) { + case INIT: + if (clockwise) { + next = ONCE_RIGHT; + wall_kick = 0; + } else { + next = ONCE_LEFT; + wall_kick = 7; + } break; + case ONCE_RIGHT: + if (clockwise) { + next = TWICE; + wall_kick = 2; + } else { + next = INIT; + wall_kick = 1; + } break; + case ONCE_LEFT: + if (clockwise) { + next = INIT; + wall_kick = 6; + } else { + next = TWICE; + wall_kick = 5; + } break; + case TWICE: + if (clockwise) { + next = ONCE_LEFT; + wall_kick = 4; + } else { + next = ONCE_RIGHT; + wall_kick = 3; + } break; + } + + piece_matrix m; + memset(m, 0, sizeof(piece_matrix)); + + for (u8 x = 0; x < 4; x++) { + for (u8 y = 0; y < 4; y++) { + if (g->current.m[y][x]) { + u8 new_x = (clockwise) ? 1 - (y - 2) : 1 + (y - 2); + u8 new_y = (clockwise) ? 2 + (x - 1) : 2 - (x - 1); + + if (g->current.t == I) { + if (clockwise) new_y--; + else new_x++; + } + + m[new_y][new_x] = 1; + } + } + } + + vec2 kick; + bool set_current = false; + bool did_kick = false; + for (u8 i = 0; i < 5; i++) { + if (g->current.t == I) { + kick = srs_wall_kicks_i[wall_kick][i]; + } else { + kick = srs_wall_kicks[wall_kick][i]; + } + g->current.pos.x += kick.x; + g->current.pos.y += kick.y; + if (check_new_matrix(g, m) > 0) { + set_current = true; + if (i > 0) did_kick = true; + break; + } else { + g->current.pos.x -= kick.x; + g->current.pos.y -= kick.y; + } + } + + if (set_current) { + /* check for tspin */ + if (g->current.t == T) { + u8 did_tspin = 1; + for (u8 i = 0; i < 4; i++) { + g->current.pos.x += basic_movements[i].x; + g->current.pos.y += basic_movements[i].y; + + if (check_new_matrix(g, m) == 1) + did_tspin = 0; + + g->current.pos.x -= basic_movements[i].x; + g->current.pos.y -= basic_movements[i].y; + } + + if (did_tspin) { + if (did_kick) g->mini_tspin = 1; + else g->tspin = 1; + } + } + + g->current.r = next; + memcpy(g->current.m, m, sizeof(piece_matrix)); + wipe_board(g); + } +} + +i8 check_new_matrix(struct cetris_game* g, piece_matrix m) { + for (u8 x = 0; x < 4; x++) { + for (u8 y = 0; y < 4; y++) { + vec2 r = (vec2){g->current.pos.x + x, g->current.pos.y + y}; + if (m[y][x]) { + if (r.x > CETRIS_BOARD_X - 1 || r.x < 0) + return 0; + + if (r.y > CETRIS_BOARD_Y - 1 || r.y < 0) + return -1; + + if (g->board[r.x][r.y].occupied && g->board[r.x][r.y].constant) + return -1; + } + } + } + return 1; +} diff --git a/core/src/test.c b/core/src/test.c index c15156a..e9ce23e 100644 --- a/core/src/test.c +++ b/core/src/test.c @@ -1,72 +1,72 @@ -#include "test.h" -#include "cetris.h" - -u8 tspin_board[20][10] = { - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 1, 1, 1, 1, 0, 0, 1, 1, 1, 1 }, - { 1, 1, 1, 0, 0, 0, 1, 1, 1, 1 }, - { 1, 1, 1, 1, 0, 1, 1, 1, 1, 1 }, - { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 } -}; - -u8 tspin_no_lines_board[20][10] = { - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 1, 1, 1, 1, 0, 0, 1, 1, 1, 0 }, - { 1, 1, 1, 0, 0, 0, 1, 1, 1, 0 }, - { 1, 1, 1, 1, 0, 1, 1, 1, 1, 0 }, - { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 } -}; - -void apply_test_board(struct cetris_game* g, enum tests t) { - u8 (*board)[20][10]; - switch (t) { - case TSPIN: - board = &tspin_board; - break; - case TSPIN_NO_LINES: - board = &tspin_no_lines_board; - break; - default: - return; - } - for (u8 y = CETRIS_BOARD_VISABLE; y < CETRIS_BOARD_Y; y++) { - for (u8 x = 0; x < 10; x++) { - if ((*board)[y - CETRIS_BOARD_VISABLE][x]) { - g->board[x][y].occupied = 1; - g->board[x][y].constant = 1; - g->board[x][y].c = COLOR_I; - } - } - } -} - +#include "test.h" +#include "cetris.h" + +u8 tspin_board[20][10] = { + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 1, 1, 1, 1, 0, 0, 1, 1, 1, 1 }, + { 1, 1, 1, 0, 0, 0, 1, 1, 1, 1 }, + { 1, 1, 1, 1, 0, 1, 1, 1, 1, 1 }, + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 } +}; + +u8 tspin_no_lines_board[20][10] = { + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 1, 1, 1, 1, 0, 0, 1, 1, 1, 0 }, + { 1, 1, 1, 0, 0, 0, 1, 1, 1, 0 }, + { 1, 1, 1, 1, 0, 1, 1, 1, 1, 0 }, + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 } +}; + +void apply_test_board(struct cetris_game* g, enum tests t) { + u8 (*board)[20][10]; + switch (t) { + case TSPIN: + board = &tspin_board; + break; + case TSPIN_NO_LINES: + board = &tspin_no_lines_board; + break; + default: + return; + } + for (u8 y = CETRIS_BOARD_VISABLE; y < CETRIS_BOARD_Y; y++) { + for (u8 x = 0; x < 10; x++) { + if ((*board)[y - CETRIS_BOARD_VISABLE][x]) { + g->board[x][y].occupied = 1; + g->board[x][y].constant = 1; + g->board[x][y].c = COLOR_I; + } + } + } +} + -- cgit v1.2.3-101-g0448