3.7 KiB
id, title, challengeType, forumTopicId, dashedName
| id | title | challengeType | forumTopicId | dashedName |
|---|---|---|---|---|
| 5e46f8d6ac417301a38fb92d | Камінь-ножиці-папір | 10 | 462376 | rock-paper-scissors |
--description--
For this challenge, you will create a program to play Rock, Paper, Scissors. A program that picks at random will usually win 50% of the time. To pass this challenge your program must play matches against four different bots, winning at least 60% of the games in each match.
Ви будете працювати над цим проєктом з нашим стартовим кодом Replit.
We are still developing the interactive instructional part of the machine learning curriculum. For now, you will have to use other resources to learn how to pass this challenge.
--instructions--
In the file RPS.py you are provided with a function called player. The function takes an argument that is a string describing the last move of the opponent ("R", "P", or "S"). The function should return a string representing the next move for it to play ("R", "P", or "S").
A player function will receive an empty string as an argument for the first game in a match since there is no previous play.
The file RPS.py shows an example function that you will need to update. The example function is defined with two arguments (player(prev_play, opponent_history = [])). The function is never called with a second argument so that one is completely optional. The reason why the example function contains a second argument (opponent_history = []) is because that is the only way to save state between consecutive calls of the player function. You only need the opponent_history argument if you want to keep track of the opponent_history.
Hint: To defeat all four opponents, your program may need to have multiple strategies that change depending on the plays of the opponent.
Розробка
Do not modify RPS_game.py. Запишіть весь свій код у RPS.py. Для розробки ви можете використати main.py, щоб протестувати свій код.
main.py imports the game function and bots from RPS_game.py.
To test your code, play a game with the play function. The play function takes four arguments:
- two players to play against each other (the players are actually functions)
- the number of games to play in the match
- an optional argument to see a log of each game. Set it to
Trueto see these messages.
play(player1, player2, num_games[, verbose])
For example, here is how you would call the function if you want player and quincy to play 1000 games against each other and you want to see the results of each game:
play(player, quincy, 1000, verbose=True)
Натисніть кнопку «run» і main.py запуститься.
Тестування
Модульні тести для цього проєкту знаходяться в test_module.py. Ми імпортували тести з test_module.py до main.py для вашої зручності. Якщо ви видалите коментар в останньому рядку в main.py, тести запустяться автоматично, коли ви натиснете кнопку «run».
Надсилання
Скопіюйте URL-адресу свого проєкту та відправте її.
--hints--
Він повинен пройти усі тести Python.
--solutions--
# Python challenges don't need solutions,
# because they would need to be tested against a full working project.
# Please check our contributing guidelines to learn more.