#Made tictactoe all by myself

24 messages · Page 1 of 1 (latest)

lusty sand
#

Hey, I've started learning c++ few days ago and I wrote tictactoe game. I'd say I made the code overcomplicated, but since it's my first c++ program, I think it's fine.

Just to clarify, I challenged myself to do it with everything I learnt so far, so I had exactly 0 help (no internet, nothing). I'm experienced with other languages (not c-like) tho, so I it would be way harder if some things didn't come naturally.
Anyways, here's the code:

#

the reason why I'm posting this, I would love if you could just point out unnecessary code and give me some tips to improve myself

#

I know I've done the checkState() function way to complicated and long, but I just couldn't figure out how to do it more efficiently

slim escarp
#

Do you want pointers on more advanced stuff you could have used or just basics?

lusty sand
#

both if you don't mind

slim escarp
#

i found a bug in void move(char player)

#

if you input invalid moves it calls move() again

#

it will take this path through the function if you enter incorrectly once and then correctly

#

the move(plrOnTheMove); at the bottom of the function doesnt have this problem since there is no code below it that is repeated

#

alright

#
  1. global variables are bad, try to not use them
#
  1. imo, it would look better if you used an enum instead of chars to mark the state of a square
#
  1. XonTheMove is a pretty bad name, so is plrOnTheMove
#
  1. you dont really check whether or not your input was alright in the start of move()
#
  1. loads and loads of blank rows and inconsistent indentation
#
  1. another idea instead of 2: (this is kinda unnecessary) if you had each square state as -1(x), 0(blank) or 1(o) you could check whether a column/row is finished by adding up all squares in that column/row. If the sum is -3 crosses won if it is 3 noughts won and otherwise no one won from that column/row
#
  1. char &_weiner = weiner; doesn't really do anything. weiner = i does the same thing.
#
  1. using namespace std is generally frowned upon
#
  1. std::array would work well for the board
harsh egretBOT
slim escarp
#

i think thats all from me 🙂

#

great job! finishing your first project is the biggest hurdle

lusty sand
#

I'll look into all those things and try to work on them, thanks a lot o7