/interviews.TicTacToe

A Tic Tac Toe game written in CodeIgniter 3.1.3 for a Senior PHP developer interview

Primary LanguagePHP

Interview Project: Tic Tac Toe

This is a Tic Tac Toe game that I wrote for a Senior PHP developer interview.

The project was created using CodeIgniter 3.1.3, bootstrap 4.0.0-alpha.6 and Doctrine 2 running on PHP 7.1.0 and Percona-Server 5.7 (Mysql Fork). Please stay away from IE... I tested it quickly on Firefox and it seemed fine. I used the latest build of Chrome while developing.

The Specification

Using the Codeigniter framework (http://www.codeigniter.com/), build a tic tac toe game with the following features:

  • Take a name for the two players and begin a new game.

  • Use basic styling for the grid using css.

  • Allow the players to click the grid to make their move, and highlight when the game is finished.

  • Store the results of each match in a MySQL database, and have a page to view the results.

  • Use the bootstrap framework to make it responsive in the following ways:

    • On mobile device, make the game full screen.
    • On desktop browser have the results of the last 5 matches on the right hand side – do this in bootstrap, not php.
  • If you have more time, then please look at making an option of playing against the computer

Prerequisites

You will need the following properly installed on your computer.

Installation

  • $ git clone https://github.com/MetaphoricalSheep/interviews.TicTacToe.git ./TicTacToe
  • $ cd TicTacToe/application
  • $ php composer.phar update
  • $ vim config/database.php
  • $ echo "create database TicTacToe" | mysql -u <user> -p<password>
  • $ php cli-doctrine.php orm:schema-tool:create
  • $ php cli.php seed:types
  • $ php cli.php seed:marvin

Issues

  • Composer complains about bcmath or zip -> $ sudo apt install php-bcmath php-zip
  • cli-doctrine.php complains about missing drivers -> $ sudo apt install php-mysql
  • cli-doctrine complains about Parse error:

? Parse error

Use PHP 7.1

Php 7.1 allows for nullable return types, you'll spot something like public function SomeFunction(string arg) : ?SomeClass in the code. The ? before SomeClass tells the interpreter that SomeClass might be null.

Running

  • $ cd path/to/project/TicTacToe/public
  • $ php -S [ip]:8000
  • Open Chrome and point it to [ip]:8000

Todo

  • The results page was a rush job. I missed it in the spec. Added it quickly as an afterthought. It needs refining.
  • Marvin (the AI) always plays on the most difficult level at the moment. I need to add different difficulty levels.
  • The history side bar hides on smaller screen sizes, but that is about the only thing that is currently responsive on this project.
  • There are no unit tests
  • Exception handling is hit and miss, more miss than hit.
  • Marvin takes his time to make his first move, despite having a brain the size of a planet. He might just be depressed. Some refactoring is needed to speed things up.

I was busy implementing a multiplayer mode, but I ran out of time. The idea is to have both players' browsers connect to a pub/sub which will feed them updates as needed. The GameApi layer (and frontend) is the only thing that needs to change to facilitate this.