Giter Site home page Giter Site logo

kevindoyleie / tictactoe Goto Github PK

View Code? Open in Web Editor NEW

This project forked from samjamesobrien/tictactoe

0.0 0.0 0.0 1.2 MB

A secured web app to play Tic Tac Toe against a dummy computer opponent, forked from https://github.com/randomvlad/TicTacToe.git and modified to provide some small interview coding challenges.

License: MIT License

Shell 0.12% JavaScript 0.59% Java 88.53% CSS 1.99% HTML 8.78%

tictactoe's Introduction

Tic Tac Toe

A secured web app to play Tic Tac Toe against a dummy computer opponent, forked from https://github.com/randomvlad/TicTacToe.git and modified to provide some small interview coding challenges.

Features & Notes

  • Play a game on a 3x3 board with an option to go first or after the computer opponent.
  • Computer opponent's AI chooses random squares, except when going first in which case the center tile is always picked.
  • User game data is persisted to an in-memory database. As long as the server is not restarted, a player can leave and return to finish an in-progress game.
  • App is secured with a username & password login. Database is seeded with one username horatio with password hertz.

Tech Stack

Technology
Language Java 11
Framework Spring Boot (v2.5)
Data Layer H2 Database, JPA & Hibernate
UI Layer HTML, CSS, Javascript, jQuery (v3.6), Bootstrap (v5), Thymeleaf
Testing JUnit 5, Mockito, AssertJ
Build Tool Gradle (v7.2)

Challenge tasks

We want to do a few things with this repo, which is forked from a working tic tac toe Spring Boot application.

1. Getting familiar with the application

1.1 Run via the gradle wrapper

Run the application from a terminal using ./gradlew bootRun and navigate to the home page http://localhost:8080/tictactoe/.

1.2 Log in

Use the username "horatio" and password "hertz".

1.3 Try to play a game

It will fail as some code isn't yet written. We'll fix that later.

1.4 Stop the application

Just stop the application from running.

2. Add a new user

This repo defines a default user that you just logged in with named "horatio".

Please add an additional user using the same pattern.

Tip: Simple implementation is fine, copy the implementation that added Horatio.

3. Fix the run.sh script

There is a run.sh and test.sh script in the top directory of the repo.

3.1 Fix the script

It isn't working for some reason when we call ./run.sh from a normal terminal, but is working when we call bash run.sh can you fix it?

Hint: Is there a problem with the file permissions?

4. Fix the code & pass the tests

The run script is fixed, but it is obvious that there are failing tests.

Tip: The tests themselves are correct and don't need to change.

Tip: Read the javadoc and the tests.

4.1 Implement the BoardUtil.getAllLines(...) method

Run the BoardUtilTest tests, they should fail

The getAllLines method is not complete, once complete the BoardUtilTest tests will pass.

4.2 Implement the GameService.evaluateGameState(...) method

Run the GameServiceTest tests, they should fail

This method is needed for the GameServiceTest to pass.

Evaluate the state of the board, has anyone won? Is it a draw? Is it in progress?

5. Play the working game

Do the steps from step 1 again, the game is working and you can play against the computer.

Play a few rounds and see if you can win, lose, draw. Is the computer playing well?

6. Improve the Computer players algorithm

The computer makes random moves against the player as it stands. That results in a poor opponent.

6.1 Enable the Computer player tests

In ComputerPlayerServiceTest enable the commented out tests, run them, some should fail.

6.2 The computer tries to block

The computer should try to play a move that blocks the player if they place two moves in a row.

e.g. in the below game, if O goes next, they should not randomly pick, but should block X.

[X, X, _]
[O, _, _]
[O, _, _]

Update the computer players algorithm to prioritise blocking 2 in a row.

6.3 The computer tries to win

The above improvement tries to block the other player winning, but what if we could win instead?

e.g. In the below game, if O goes next, because of the previous improvment it might try to block X, but it could win outright by making 3 in a row.

[X, X, _]
[O, O, _]
[_, _, _]

Update the computer players algorithm to prioritize winning over blocking.

7 Play again

Try to beat the computer now!

8 (Optional) Are there any refactors or other improvements you could suggest?

No need to implement, just identify some improvements you might suggest.

tictactoe's People

Contributors

randomvlad avatar kevindoyleie avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.