Git Product home page Git Product logo

tic-tac-tester2's Introduction

Tic-Tac-Tester.js

This script will test the game logic of your tic tac toe game. To use it you will need to include it in your html file after your main tic-tac-toe script.

Do not open test-the-tester.js file. It contains one implementation of Tic Tac Toe and is just there to ensure that the tests work. Ignore it and write your own code!

You will need to declare the following functions in the global scope:

playTurn(index)

It should take one parameter which is a zero-based index to your grid, indicating where the current player's token should be played. It should return a boolean value to indicate whether the move was allowed or not - true if it was successful, false otherwise e.g. if the square is already taken or the game is over.

isGameOver()

It should return a true or false if the game is over.

whoWon()

It should return 0 if the game is not yet finished. Else it should return either 1 or 2 depending on which player one. It should return 3 if the game is a draw.

restart()

It should restart the game so it can be played again.

It is assumed that the turns of the player will be automatically changed after an allowed move.

The application will console log all the passed or failed test.

General tips

Create a new .js file that contains your functions, and replace the <script src="./testing-the-tester.js"></script> (example.html, line 6) tag with the path to your new file.

You might want to create a few variables to store information about the current state of the game. Eg. an array to represent the tic tac toe grid (eg. var grid = [...]), and a variable to track who the current player is (1 or 2), etc.

There is no need to, but you can, look at the code in the tic-tac-tester.js file. This file contains code that will make use of the 4 functions you define (ie. it will call these functions) and check whether they return answers that they are supposed to. In other words, it will run all your functions multiple times to check that they work.

So for example if playTurn(0) is called by the code in tic-tac-tester.js, and your grid array indicates that it was previously already clicked, then whoWon() should return 0 (because whoWon() is supposed to do that, according to the specification above).

tic-tac-tester2's People

Contributors

primaulia avatar

Watchers

James Cloos 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.