Skip to content

A text based implementation of the standard game Twixt

License

Notifications You must be signed in to change notification settings

tejavvo/twixt-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Twixt CLI

This is a text based C implementation of the twixt board game, as part of the CPro'25 course IIIT-H.

Referances given can be found here:

  1. Project Docs: https://www.notion.so/CPro-25-Project-2a110a71ff29805e81d7f7f95ea85a70
  2. Rules: https://youtu.be/dIyuVS3xRQ0?si=_qYFqihhfrxKRBRq
  3. Online player: https://twixtlive.com/Play.aspx
 twixt-cli/
├──  include/
│   ├──  log.h
│   ├──  macros.h
│   ├──  moves.h        // Game Logic protoypes
│   ├──  state.h
│   └──  utility.h      // Rendering function prototypes, macros, and constants
├──  LICENCE.md
├──  makefile
├──  obj/
│   ├── (...)              // Object files
├── 󰂺 README.md
├── 󰣞 src/
│   ├──  error.c   // Display user messages (primarily errors)
│   ├──  links.c   // Handles Win condition and auxillaries
│   ├──  log.c
│   ├──  main.c    // Handles game loop and input
│   ├──  moves.c   // Handles logic for each possible move 
│   └──  ui.c      // Rendering layer: draws board, manages colors
├── 󰡯 twixt <-- Main Executable
└──  twixt.log     // Log file -- Autogenerated

The screen and colours are refreshed and reprinted using ANSI charector codes, the size of the board depends on the SIZE macro defined in include/macros.h

To compile and run, simply run make and ./twixt. It is compiled with gcc however to change the compiler change the CC flag in the makefile (and their repective flags), or just compile on your own

On Linux:

mkdir -p obj/
for f in src/*.c; do
    gcc -Wall -Wextra -O1 -c "$f" -o "obj/$(basename "$f" .c).o"
done

gcc -O1 obj/*.o -o twixt
./twixt

To clean, you can run make clean Please note the make file will not clear your twixt.log file.

Playing the game

To play the game, enter a Row number and a Column number or Column alphabet (regardless of case) to select your cell, when it is your color's turn.

You can:

  • Place a peg: p <number> <number|alphabet> or place <number> <number|alphabet>
  • Remove a peg: u <number> <number|alphabet> or unplace <number> <number|alphabet>
  • Link two pegs: l <number> <number|alphabet> <number> <number|alphabet> or link <number> <number|alphabet> <number> <number|alphabet>
  • Unlink two pegs: x <number> <number|alphabet> <number> <number|alphabet> or unlink <number> <number|alphabet> <number> <number|alphabet>
  • Show all links: v | viewlinks
  • Show manual: h | help

You cannot place at the corners or you're opponent's column.

To quit, simply type "q", "exit or "quit" in the promt and enter.

There is also a twixt.log file (it is autogenerated), which keeps track of all your moves and outputs. to disable this, please set the macro in log.h to 0.

Future Work

  • Draw links
  • Auto link
  • Place board and commands side by side
  • take input with p A2 or p 2A or p 2 A as well
  • Undo any change / only undo unplace and unlink -- since it is the longest
  • Points system + scoreboard
  • Overall colourise fonts
  • Main menu

This project is licensed under the MIT License.

About

A text based implementation of the standard game Twixt

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •