Giter VIP home page Giter VIP logo

tic-tac-toe's Introduction

Tic-tac-toe

A mini game tic-tac-toe implemented in C.

Problem statement

To ask players to input tokens on the plate using the numeric keys. Since the 9 squares on the plate are marked with integers from 1 to 9 respectively, players need to input tokens by tapping numeric keys 1 - 9. The program should judge that player 1 or player 2 have won the game when 3 tokens with the same type are in a line. And the program should consider it as a draw when the 9 squares are filled with tokens but without the 3 same type tokens in a line. Besides, illegal inputs should be detected and reported, which are any inputs other than the integer numbers from 1 to 9. Repeated inputs are also considered as illegal and will be reported if input.

Analysis

(Assume that the user only inputs valid data.)

Inputs

Integer numbers from 1 to 9

Outputs

Two kinds of tokens O and X in 9 squares separately

Additional requirements or constraints

The same number cannot be chosen repeatedly

Design

  1. Define 2 variables: row and column
    row is assigned as 7 and it represents the numbers in a single row.
    column is assigned as 3 and it represents the numbers in a single column.
  2. Declare a series of functions and variables:
    char p [row] [column] means declaring a 2D array of row*column.
    int board(char p [row] [column]) means that the 2D array should be inserted into an assigned integer as the game board.
    char order (int a) means that an integer a should be inserted into a character order.
    int judge(char p [row] [column]) means that the 2D array should be inserted into an integer as a judgment basis.
    int sum = 1 represents an integer assigned as 1.
    int operate(char p [row] [column], int sum) means declaring a function operate with elements char p row column and int sum.
    int x represents an integer x, which refers to a number in a single row, or the number of columns.
    int y represents an integer y, which refers to a number in a single column, or the number of rows.
    char s = 48 means assigning a character s as 48 according to ASCLL, which equals to 0 decimal.
    int ch represents an integer ch.
    int num = 0 means that the integer is assigned as 0.
  3. Design an opening interface of the game.
  4. Build a single judging loop to guide players to start the game and lead to the main interface of the game.
  5. Print out the game board in the main interface using defined 2D array.
  6. Define the game rules about placing the tokens.
  7. Evaluate the logical judgments to define whether the game is a win, a lose or a draw.
  8. Detect and report if there is an illegal input.

Demonstration

Gameboard

Image

'O' wins

Image

'X' wins

Image

Draw

Image

Illegal Input

Image

tic-tac-toe's People

Contributors

weiyi-li avatar

Watchers

 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.