Skip to content
Snippets Groups Projects
Select Git revision
  • main default protected
1 result

naughts-and-crosses-c

  • Clone with SSH
  • Clone with HTTPS
  • Name Last commit Last update
    README.md
    naughts_and_crosses_c++

    presentation questions:

    1. how to compile a c++ file?
    • in vs code i would use the built in terminal and follow ctrl+shift+b and run the g++ command g++ naughtsandcrosses.cpp -o naughtsandcrosses ./naughtsandcrosses
    1. What is this line of code doing?
    • the example code mark = (player == 1) ? 'X' : 'O'; -this operator assigns the 'X' to mark if the player is 1, otherwise the player is 2 with 'O' setting the players symbols.
    1. what is this function doing?
    • example code
    int checkwin() {
        if (sqaure[1] == square[2] == sqaure[3]) return 1;} ...

    this checks all possible win combinations over all directions. it also returns a 1 if a player wins, 0 for a draw and -1 to continue the game.

    1. how does a for loop work in c++?
    • a for loop is a tool to utilise repitition that allows you to write code that can be executed a specific number of times. this could have been used to simplify the win-check in my naughts and crosses code but i used if-else chains.