Play Tic-tac-toe on your keyboard, against your keyboard!
This is an implementation of Tic-tac-toe that can run on any qmk based keyboard. You can play against your keyboard in any text editor of your choice. The keyboard writes out the board as normal keystrokes and waits for your input. It then deletes the whole board by pressing backspace multiple times and writes out the new board state. Just enter the Tic-tac-toe layer and select your move by pressing 1 to 9.
Tested on an Ergodox.
- Copy
tictactoe.c
andtictactoe.h
into the same directory as yourkeymap.c
- Add
SRC += tictactoe.c
to yourrules.mk
- Optionally add
#define USB_POLLING_INTERVAL_MS 5
to yourconfig.h
to speed up the keypresses
Make the following changes to your keymap.c
:
- Add
#include "tictactoe.h"
- Add a new layer that contains
KC_1
toKC_9
and a key to switch away from this layer - Add a mapping to switch to the new layer. I.e.
TG(TIC_TAC_TOE_LAYER)
- Adjust
TIC_TAC_TOE_LAYER
intictactoe.h
to the new layer number - Add the following code at the start of
process_record_user
:
if (layer_state_is(TIC_TAC_TOE_LAYER) && record->event.pressed) {
makeMoveKC(keycode);
return false;
}
- Add the follwoing code at the start of
layer_state_set_user
:
if (IS_LAYER_ON_STATE(state, TIC_TAC_TOE_LAYER)) {
initializeTicTacToe();
}
Done! Switching to the new Tic-tac-toe layer should start the game.