Skip to content

Commit

Permalink
'Quarto!' ver 0.03
Browse files Browse the repository at this point in the history
✨ Improve title visuals
✨ Instruction
👍 Support 2x2 rule
👍 Add originator's name to credit
  • Loading branch information
obono committed Sep 30, 2019
1 parent cc16290 commit 10f029d
Show file tree
Hide file tree
Showing 3 changed files with 258 additions and 37 deletions.
16 changes: 12 additions & 4 deletions quarto/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define FPS 60
#define APP_TITLE "QUARTO!"
#define APP_CODE "OBN-Y08"
#define APP_VERSION "0.02"
#define APP_VERSION "0.03"
#define APP_RELEASED "OCTOBER 2019"

enum MODE_T {
Expand All @@ -23,9 +23,16 @@ enum GAME_MODE_T {
GAME_MODE_2PLAYERS,
};

#define SETTING_BIT_THINK_LED 0x1
#define SETTING_BIT_SCREEN_INV 0x2
#define SETTING_BIT_HINT 0x4
#define BOARD_SIZE 4
#define BOARD_EMPTY 0xFF
#define PIECE_ATTRS 4
#define TURN_MAX (BOARD_SIZE * BOARD_SIZE)
#define PIECE_MAX (1 << PIECE_ATTRS)

#define SETTING_BIT_2x2_RULE 0x1
#define SETTING_BIT_THINK_LED 0x2
#define SETTING_BIT_SCREEN_INV 0x4
#define SETTING_BIT_HINT 0x8

/* Typedefs */

Expand Down Expand Up @@ -88,6 +95,7 @@ void drawTitle(void);
void initGame(void);
MODE_T updateGame(void);
void drawGame(void);
void drawPiece(int16_t x, int16_t y, int16_t piece);

/* Global Variables */

Expand Down
36 changes: 24 additions & 12 deletions quarto/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@

/* Defines */

#define BOARD_SIZE 4
#define BOARD_EMPTY 0xFF
#define PIECE_ATTRS 4
#define TURN_MAX (BOARD_SIZE * BOARD_SIZE)
#define PIECE_MAX (1 << PIECE_ATTRS)

#define ANIM_COUNTER_MOVE 16
#define ANIM_RESOLUTION (ANIM_COUNTER_MOVE * ANIM_COUNTER_MOVE)

Expand Down Expand Up @@ -72,7 +66,7 @@ static void drawMovingPiece(void);
static void drawRestPieces(bool isFullUpdate);
static void drawRestPiecesUnit(int16_t x, uint8_t piece, bool isDrawHint);
static void drawResult(bool isFullUpdate);
static void drawPiece(int16_t x, int16_t y, int16_t piece);
// void drawPiece(int16_t x, int16_t y, int16_t piece);
static void drawCursor(int16_t x, int16_t y);

static bool cpuThinking(void);
Expand Down Expand Up @@ -504,6 +498,12 @@ static bool isWinMove(GAME_T *p, uint8_t x, uint8_t y, bool isJudge)
bool ret = isLined(p, x, 0, 0, 1, isJudge) || isLined(p, 0, y, 1, 0, isJudge);
if (!ret && x == y) ret = isLined(p, 0, 0, 1, 1, isJudge);
if (!ret && x == BOARD_SIZE - y - 1) ret = isLined(p, BOARD_SIZE - 1, 0, -1, 1, isJudge);
if (record.settings & SETTING_BIT_2x2_RULE) {
if (!ret && x > 0 && y > 0) ret = isLined(p, x - 1, y - 1, 0, 0, isJudge);
if (!ret && x < BOARD_SIZE - 1 && y > 0) ret = isLined(p, x, y - 1, 0, 0, isJudge);
if (!ret && x > 0 && y < BOARD_SIZE - 1) ret = isLined(p, x - 1, y, 0, 0, isJudge);
if (!ret && x < BOARD_SIZE - 1 && y < BOARD_SIZE - 1) ret = isLined(p, x, y, 0, 0, isJudge);
}
return ret;
}

Expand All @@ -519,15 +519,27 @@ static bool isLined(GAME_T *p, uint8_t x, uint8_t y, int8_t vx, int8_t vy, bool
for (uint8_t j = 0; j < PIECE_ATTRS; j++) {
if (piece & 1 << j) attrCnt[j]++;
}
x += vx;
y += vy;
if (vx == 0 && vy == 0) {
int8_t b = i & 1;
x += 1 - b * 2;
y += b;
} else {
x += vx;
y += vy;
}
}
for (uint8_t i = 0; i < PIECE_ATTRS; i++) {
if (attrCnt[i] == 0 || attrCnt[i] == BOARD_SIZE) {
if (isJudge) {
for (uint8_t i = 0; i < BOARD_SIZE; i++) {
x -= vx;
y -= vy;
if (vx == 0 && vy == 0) {
int8_t b = i & 1;
x += 1 - b * 2;
y -= 1 - b;
} else {
x -= vx;
y -= vy;
}
linedPiecesPos |= 1 << (y * BOARD_SIZE + x);
}
}
Expand Down Expand Up @@ -746,7 +758,7 @@ static void drawResult(bool isFullUpdate)
}
}

static void drawPiece(int16_t x, int16_t y, int16_t piece)
void drawPiece(int16_t x, int16_t y, int16_t piece)
{
arduboy.drawBitmap(x, y, imgPiece[piece], IMG_PIECE_W, IMG_PIECE_H, WHITE);
}
Expand Down
Loading

0 comments on commit 10f029d

Please sign in to comment.