xemeds / obstruction-game Goto Github PK
View Code? Open in Web Editor NEWConsole version of the pen and paper game Obstruction with the Minimax algorithm.
License: MIT License
Console version of the pen and paper game Obstruction with the Minimax algorithm.
License: MIT License
Hi just saw your game on reddit. Program looks nice written.
I am an embedded programmer and use C. I don't know much about CLI and strings. I am deeper. ;)
Some of parts of my toolchain are written in python so may understand your thinkings.
I will write some "issues" down, so may you can "improve" your code or just think about my suggestions.
(I will not repeat this introducing words...)
Your board size can be changed by
#define BOARD_SIZE 6
but the grid print doesn't adapt, it will always will a 6x6 grid.
if (board[y][x] == 'X')
printf("\033[34m\033[1m %c ", board[y][x]);
Why using printf with variable replacement while the replacement is always a fixed value. (in this Example 'X'.
This will may speed up your programm.On a 3GHz processor, in a CLI this may doen't matter, but hey, it's possible. ;)
Don't forget curly braces. Especially if you are a Python programmer. If you switch between Python and C you easily forget the braces if you add a second statement to the if.
if (board[y][x] == ' ')
can_play = 1;
Instead of 'X' 'O' and ' ' you can create an enum with states like 'player_A', 'player_B' or 'free'. You can even introduce 'blocked' state.
This makes code more readable and splits 'data' better from 'view'. So you can introduce some symbol or color picking at the beginning of the game. Or you can change from CLI to a real GUI or 3d animation without changing your core game engine. ;)
obstruction-game/obstruction.c
Line 144 in fbb61a7
if (!(len == 2) || !('a' <= move[0] && move[0] <= 'f') || !('1' <= move[1] && move[1] <= '6'))
Or if you plan to be more flexible with your grid size and your 'view' write a convert_CLI_input function which will return a x and y coordinates. (To do this, you have to define a costom type or a call by reference with x and y parameters).
I don't know what \033[0;36m
means, Some control or color instructions maybe. So i must google it.
Something like a macro #define CLI_CYAN_COLOR \033[0;36m
make your code easily understandable. Trust me in 6 month you don't know the color codes any more and you must google by yourself.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.