Coding standard
This commit is contained in:
parent
2bf1f009d7
commit
9fd4885411
78
doc/coding_standard.txt
Normal file
78
doc/coding_standard.txt
Normal file
@ -0,0 +1,78 @@
|
||||
|
||||
must do's:
|
||||
general:
|
||||
c++17 targetted standard
|
||||
115 max line length
|
||||
prefer // over /**/
|
||||
format pointers as `char* thing;`
|
||||
tabs not spaces
|
||||
c++ casts
|
||||
spaces around assignment, comparison, and arithmetic operators
|
||||
spaces after semicolon in for loop
|
||||
spaces after comma operator and after parameter commas
|
||||
const wherever possible (const-correctness)
|
||||
pass by pointer or by reference
|
||||
prefer reference over pointer
|
||||
functions:
|
||||
50 max length
|
||||
comments max 2 lines
|
||||
no void in parameter list: void func(){}
|
||||
brace formatting:
|
||||
void function(void){
|
||||
|
||||
}
|
||||
if(thing){
|
||||
|
||||
}else if(thing){
|
||||
|
||||
}else{
|
||||
|
||||
}
|
||||
for(){
|
||||
|
||||
}
|
||||
switch(case){
|
||||
case 1:
|
||||
break;
|
||||
}
|
||||
struct thing {
|
||||
int thingy;
|
||||
};
|
||||
union thing {
|
||||
int thingy;
|
||||
};
|
||||
class thing
|
||||
{
|
||||
private:
|
||||
int thingy;
|
||||
public:
|
||||
void func(void);
|
||||
};
|
||||
enum thing{
|
||||
stuff,
|
||||
};
|
||||
|
||||
|
||||
no-no's:
|
||||
goto (except when breaking from inner loop)
|
||||
for(){
|
||||
for(){
|
||||
goto breakinner;
|
||||
}
|
||||
}
|
||||
breakinner:;
|
||||
|
||||
using c++ exceptions
|
||||
using <iostream>
|
||||
asm blocks
|
||||
use of 'friend'
|
||||
nested ternary
|
||||
ternary outside of variable initialization
|
||||
lambdas
|
||||
malloc/free
|
||||
#pragma
|
||||
structured bindings
|
||||
range based for loops
|
||||
`class` in template parameter list
|
||||
struct keyword before an object declaration
|
||||
struct game_state* gl; //bad boi
|
||||
30
src/main.cpp
30
src/main.cpp
@ -1,6 +1,6 @@
|
||||
#include <cstdio>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
|
||||
// 0 | 1 | 2
|
||||
// ---------
|
||||
@ -12,7 +12,7 @@
|
||||
|
||||
int get_player_input(){
|
||||
//TODO get player input
|
||||
return rand()%9;
|
||||
return rand() % 9;
|
||||
}
|
||||
|
||||
struct game_state {
|
||||
@ -20,26 +20,26 @@ struct game_state {
|
||||
char board[TILE_COUNT];
|
||||
};
|
||||
|
||||
void game_turn(struct game_state * gs,int player_input){
|
||||
void game_turn(game_state& gs, int player_input){
|
||||
if(player_input > TILE_COUNT && player_input < 0)
|
||||
fprintf(stderr,"ERR: player input not in range.");
|
||||
if(!gs->board[player_input])
|
||||
gs->board[player_input]='O';
|
||||
gs->turn++;
|
||||
if(!gs.board[player_input])
|
||||
gs.board[player_input] = 'O';
|
||||
gs.turn++;
|
||||
}
|
||||
|
||||
void display_game_state(struct game_state * gs){
|
||||
printf("turn %i:\n",gs->turn);
|
||||
for(int i=0;i<TILE_COUNT;i++){
|
||||
printf("[%i]:%c\n",i,gs->board[i]);
|
||||
void display_game_state(const game_state& gs){
|
||||
printf("turn %i:\n", gs.turn);
|
||||
for(int i = 0; i < TILE_COUNT; i++){
|
||||
printf("[%i]:%c\n", i, gs.board[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
srand(time(NULL));
|
||||
struct game_state gs = {0};
|
||||
while(gs.turn<TILE_COUNT){
|
||||
game_turn(&gs,get_player_input());
|
||||
display_game_state(&gs);
|
||||
game_state gs = {0};
|
||||
while(gs.turn < TILE_COUNT){
|
||||
game_turn(gs, get_player_input());
|
||||
display_game_state(gs);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user