You need to successfully solve this challenge, if you want to snatch yourself an apprenticeship at MΓNSMEDIA GmbH as a Fachinformatiker*in Anwendungsentwicklung. πΎ π€ π
Tic-tac-toe, noughts and crosses, or Xs and Os is a two-player game, that you're probably already familiar with.
The game board consists of 9 empty spaces, aligned in a three-by-three grid. Players alternately place the marks (:x:) and (:o:) in one of the empty spaces.
The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row is the winner. If no winner has been decided after all spaces have been filled, the game ends in a draw.
A NassiβShneiderman diagram or structogram is a diagram to show program drafts as a method for structural programming.
A structogram contains the following structural blocks, that are nested inside or combined with each other:
Every process (or chain of commands), a program should do, are written inside a rectangle block.
If the condition is met (true), instruction 1 will run.
If the condition isn't met (false), instruction 2 will run. Instruction blocks can also have multiple instructions.
After executing the code inside the loop at least one time the condition gets checked the first time. If this is true, the loop gets repeated.
We started creating a structogram for the Tic-tac-toe game, but your future trainer Malte isn't sure about the contents from the parts (1), (2), (3), (4), (5), (6), (7)
.
Can you help him?
Please write down your solutions and include them in your email to us when completed.
Now that you know how Tic-tac-toe works, we want to code it together. Don't worry. Even if you have little to no programming experience, we will get there together. π We want to see and work together on your source code. We use the platform GitHub to share source code freely.
- You already own a Github-Account or you create yourself a free GitHub-Account
- After signing in to GitHub.com:
- Copy our source code to your GitHub-Account. Just click here.
- Please set the visibility of the new repository - as default - to 'Public'.
- Now scroll down the newly created GitHub repository until you see these instructions.
- You continue from this point in the repository you have just created.
- Open Gitpod
- Click
Continue with GitHub
, chooseAuthorize gitpod-io
and login with your GitHub-credentials. - Make sure you are on https://gitpod.io/workspaces.
- By clicking
New Workspace
you create a new programming environment. - In the opening dialog, select the address of your newly created repository.
- The GitPod workspace should open itself.
- Choose
Don't wait for prebuild
- Gitpod opens, this can take some minutes π³. Please be patient.
- In the meantime open https://gitpod.io/integrations
- In the row
GitHub github.com
click thethree dots
followed byEdit Permissions
- Additionally select
public_repo
andrepo
and save withUpdate permissions
. - Confirm your changes with
Authorize gitpod-io
and your password if applicable - Now open these instructions. To do this, right-click on the file
README.md
and then onOpen Preview
. - Continue with the instructions in your Gitpod programming environment.
Your Tic-tac-toe webapp consists of a frontend and backend part.
As frontend, we use a tool called Swagger
, so we can try out API's with a graphical interface.
Swagger is already open, as you open GitPod's programming environment.
As backend, we use a PHP-App, based on the framework Laravel.
We have prepared a function that displays this game's copyright. Β©οΈ
Try this API method to display the game's copyright:
- In Swagger, click on
/copyright
. - Click on the button
Try it out
. - Send this request by clicking on
Execute
. - You can view the output with the current copyright at
Response body
.
βπΌ Change copyright:
- Open file app/app/App/Http/Controllers/CopyrightController.php in Gitpod.
- You can find the copyright in a string format on line 18.
- Use the ASCII generator linked in
CopyrightController.php
to create your personal copyright. - Replace our copyright
By MΓNSMEDIA GmbH
with your own copyright. - Try your new copyright with Swagger!
- You need to save your changes, also named - commit (next section).
- Click on the Tab
Source Control
on the left or you can press the keys Strg+Shift+G together. - You can type a message above to describe your changes as detailed and meaningful as possible. Please write your message in English, even if you are a native German speaker.
- Save your message with Strgβ
- Click on
Yes
in the pop-up window to add all your changes to your commit. - Click on the button
Sync changes
, to upload your changes to GitHub. Confirm withOK
. - π You have done your first Git-Commit! π
You can't play against the bot programmed by the MΓNSMEDIA team yet.
It is still missing the logic it needs when the /play
API route is called.
Here is the structogram for one of your turns with the play()
method.
To-do:
- Take your time to look at the structogram for one of your turns!
- We have highlighted the parts that you still need to implement in the structogram.
- In file app/app/App/Http/Controllers/GameController.php the
play()
method on line 144 still needs some logic.- Please complete the missing logic. We left some comments in the source code to help you get started.
- Now test it in Swagger. The function there is also called
/play
. - β To reset the scoreboard, you can use the
DELETE /board
method in Swagger - β
Create a commit (see above
Create commit
) - π Click the button
Sync changes
to upload your changes to GitHub.
We have already written a π€ (bot) for you, so you can play against him.
Open Swagger and alternate between the /play
and /play-bot
API route (the first turn is yours).
Currently, you or the bot can play multiple turns in a row, although you are supposed to take turns. Of course, it's no fun like that π!
To-do:
- In file app/app/App/Http/Controllers/GameController.php the
isAllowedToPlay()
method on line 144 still needs some logic.- Please complete the missing logic. We left some comments in the source code to help you get started.
- Thoroughly test your changes in Swagger.
- β
Create a commit (see above
Create commit
) - π Click the button
Sync changes
to upload your changes to GitHub.
Currently, the game is unable to display a winner.
Now it's your task, to do this.
To-do:
- Currently, the method
whoHasWon()
in app/app/App/Http/Controllers/GameController.php at line 104 has no game logic.- Add the missing logic. We created some hints for you as comments in the code.
- Test your changes with Swagger as detailed as possible.
- β
Create a commit (see above
Create commit
) - π Click on
Sync changes
to upload your changes to GitHub.
You had fun by solving these small tasks above and you want more? Ok, no problem π!
The method someoneHasWon()
at app/app/App/Http/Controllers/GameController.php is currently ugly.
Can you simplify this, by using some loops?
It can be useful, to look at public-methods from $game
:
app/app/Components/GameBoard/GameBoard.php
To-do:
- Make method
someoneHasWon()
prettier - Test your changes with Swagger as detailed as possible.
- β
Create a commit (see above
Create commit
) - π Click on
Sync changes
to upload your changes to GitHub.
Think about, what you need to change, so we can play a 4x4 Tic-tac-toe. Also look closer at the class app/app/Components/GameBoard/GameBoard.php.
To-do:
- Try to make a 4x4 Tic-tac-toe
- You will need your changes from task 7.)
- Test your changes with Swagger as detailed as possible.
- β
Create a commit (see above
Create commit
) - π Click on
Sync changes
to upload your changes to GitHub.
Once you are done, sent your solution for task 1 and your GitHub-Repository link via E-Mail.
We will analyse your solution and if you are one of the 5 best applicants, we will invite you to a personal meeting, so we can get to know you better.
See you soon!