Giter VIP home page Giter VIP logo

cyrilcolinet / cpe_matchstick_2017 Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 56 KB

:fire: Matchstick epitech project. Project based on the famouse matchsticks game. The goal is to leave the last stick to the other player (in this case, to the IA)

Makefile 12.28% C 56.97% C++ 30.75%
epitech epitech-project matchstick mrlizzard cpe elementary-programming c random time video-game game promo-2022 2017-2018 unit travis

cpe_matchstick_2017's Introduction

🔥 Matchstick - Leave the last matchstick!

  • Binary name: matchstick
  • Repository name: CPE_matchstick_2017
  • Repository rights: ramassage-tek
  • Language: C
  • Compilation: via Makefile, including re, clean and fclean rules

Subject

This project is based on a very famous game based on matchsticks.
There is a certain number of matchstick lines.
The two players take turns; each player can, on a same line, take one or several matchsticks.
The losing player is the one to take the last matchstick.

The goal of the project is to create a program that you can play against. The basic version must generate a game board with n matchstick lines (1 < n < 100) and have a simple interface so that the user could play against the computer.

The number of lines is given as parameter to the program. The second parameter of the program indicates the maximum number of matches that can be taken out each turn (must be > 0).
When matchsticks are removed, they must be removed starting from the right (like in the example below).
The user will always start the game.

The program’s output (error messages included) must correspond to the examples below. Error messages which happens during a game and which are destined to the player must be displayed on the standard output.
In case of bad input, you must ask for the line by displaying Line: " again, and it’s up to the player to indicate again the line he/she wants to play on.

❗ If the user wins, the program must return 1.
If the AI wins, it must return 2.

Bonus

Here is a list of bonuses you may implement (in the bonus, built with a separate Makefile’s rule):

  • a graphical interface,
  • a more complete game, with score and several levels of difficulty,
  • a human-machine interface device (such as a leap motion for instance) to select and remove the matchsticks.

Examples

∼/B-CPE-200> ./matchstick 4 5
*********
*   |   *
*  |||  *
* ||||| *
*|||||||*
*********

Your turn:
Line: 4
Matches: 2
Player removed 2 match(es) from line 4
*********
*   |   *
*  |||  *
* ||||| *
*|||||  *
*********

AI's turn...
AI removed 2 match(es) from line 3
*********
*   |   *
*  |||  *
* |||   *
*|||||  *
*********

Your turn:
Line: 1
Matches: 1
Player removed 1 match(es) from line 1
*********
*       *
*  |||  *
* |||   *
*|||||  *
*********

AI's turn...
AI removed 1 match(es) from line 2
*********
*       *
*  ||   *
* |||   *
*|||||  *
*********

Your turn:
Line: 12
Error: this line is out of range
Line: 2
Matches: 2
Player removed 2 match(es) from line 2
*********
*       *
*       *
* |||   *
*|||||  *
*********

AI's turn...
AI removed 2 match(es) from line 4
*********
*       *
*       *
* |||   *
*|||    *
*********

Your turn:
Line: 4
Matches: 7
Error: you cannot remove more than 5 matches per turn
Line: 3
Matches: 1
Player removed 1 match(es) from line 3
*********
*       *
*       *
* ||    *
*|||    *
*********

AI's turn...
AI removed 2 match(es) from line 3
*********
*       *
*       *
*       *
*|||    *
*********

Your turn:
Line: 4
Matches: 2
Player removed 2 match(es) from line 4
*********
*       *
*       *
*       *
*|      *
*********

AI's turn...
AI removed 1 match(es) from line 4
*********
*       *
*       *
*       *
*       *
*********
I lost... snif... but I'll get you next time!!

∼/B-CPE-200> echo $?
1
∼/B-CPE-200> ./matchstick 2 10
*****
* | *
*|||*
*****

Your turn:
Line: 1
Matches: 1
Player removed 1 match(es) from line 1
*****
*   *
*|||*
*****

AI's turn...
AI removed 2 match(es) from line 2
*****
*   *
*|  *
*****

Your turn:
Line: 2
Matches: 1
Player removed 1 match(es) from line 2
*****
*   *
*   *
*****
You lost, too bad...

∼/B-CPE-200> echo $?
2
∼/B-CPE-200> ./matchstick 2 5
*****
* | *
*|||*
*****

Your turn:
Line: 0
Error: this line is out of range
Line: %

∼/B-CPE-200> echo $?
0
# In the previous example, the last input was an EOF (you can simulate it with the keyboard combination ctrl+d).
∼/B-CPE-200> ./matchstick 2 5
*****
* | *
*|||*
*****

Your turn:
Line: aze
Error: invalid input (positive number expected)
Line: 2

...

*****
* | *
*|  *
*****

Your turn:
Line: 1
Matches: 0
Error: you have to remove at least one match
Line: 1
Matches: aze
Error: invalid input (positive number expected)
Line: 1
Matches: 3
Error: not enough matches on this line

Authorized functions

  • read, write, malloc, free, time, getpid, random, srandom

❗ srand and rand is not the same function of srandom and random!

cpe_matchstick_2017's People

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.