Due to numerous requests from readers, a large series of articles on the use of serverless computing technology to develop a real application begins. This cycle will cover application development, testing and delivery to end users using modern tools: application microservice architecture (in a serverless version, based on
What is "Epics"?
This is a variant of the game "Mafia", it is also "Werewolf". It is based on a team game, in which the participants must learn step by step who is who and try to win. Unfortunately, when playing online, such an important component of the game as personal interaction disappears, and the rules of the classic "Mafia" are quite simple, so other characters are usually added for a more non-linear and interesting gameplay, but in general, the main features of the original "Mafia" are retained. for example, the change of day and night, moves only at night, as well as alliances between participants. Also, an important difference between the game on the network is that the host (aka the Game Master, Storyteller) is usually a computer program.
Description of the game
The rules of the game I want to implement are taken from an old irc bot that I kept in my personal archive about 10 years ago. "Epics" has a backstory, which begins each game:
In a faraway kingdom, in a faraway state, beyond the seven seas, several villages lived for themselves, and in them Good fellows ΠΈ Red girls. They sowed bread, and went to the surrounding woods to pick mushrooms and berries... And it went on like this from century to century, until a terrible catastrophe shook the Earth and evil began to spread around the world! The nights became long and cold, and in the dark, evil and terrible creatures roamed the forest and wandered into the village. Arrived from somewhere The Dragon and got into the habit of stealing the Red Maidens and taking everything of value from the villagers. Harmful and greedy Baba Yaga, who flew in on a stupa from distant forests, confused the minds of the inhabitants, and even some people abandoned their craft and went into the forest to rob, put together a gang there. Likhodey met Goblin, who knew how to turn into trees and bushes, he began to follow the peaceful villagers and serve the robbers, sniffing out if the Good fellows were up to something to rid their settlements of evil spirits. Good fellows and Red girls, tired of the raids of the Robbers, but terrible deaths at the hands of a terrible Dashing of the One-Eyed, collected gold and invited a famous wrestler from a neighboring city - Ivan Tsarevichwho promised to rid the village of robbers. In a clearing in the forest, Ivan saved from inevitable death gray wolf, who fell into the pit-trap of the Robbers. In return, the Wolf promised to inform the Tsarevich about various forest evil spirits. A famous healer passed by Vasilisa the Wise, and when she saw trouble, she remained to nurse the inhabitants who suffered from dashing attacks. A black palace appeared behind the forest, in which, according to rumors, Koschei the Deathless, every night he visited the villages and bewitched the Good Fellows and the Red Maidens so that they would not dare to disobey his order, they did everything as he said. And settled in the Lifeless Forest Cat Baiyun, and everyone who met him fell asleep after his tales or died from his iron claws.
Far Far Away kingdom
As you can see, the players are divided into several groups:
- civilians (Good fellows, Red Maidens, Ivan Tsarevich, Gray Wolf and Vasilisa the Wise)
- robbers (actually robbers, as well as Baba Yaga and Leshy)
- independent (Snake-Gorynych, Likho One-Eyed, Princess-Frog, Koshchey Immortal, Kot-Bayun)
The goal of the game, as mentioned above, is to stay alive and win. The opponents must somehow leave the game, and the independents must also stay alive until the end of the game. The game has gold, a kind of in-game currency that players earn only within the game. Winners receive gold. The more gold, the higher the player's rating.
I will dwell a little more on the description of the characters.
Good fellow
Red Maiden
Good fellow ΠΈ Red Maiden - the most massive and the main role in the game. These are civilians who sleep at night and work during the day. At night, they are attacked by one of the robbers, the Serpent Gorynych and other roles, and Vasilisa the Wise heals them. With some, small probability, the Good Guy or the Red Maiden can survive the attack without damage (perhaps losing gold in the process), but everyone will recognize the player's alias the next day after the attack by the defense. At night, these players do not make any moves, but analyze the game situation based on messages in the game chat. During the day, these players decide by voting which of them is not the Good Guy or the Red Maiden. The player with the most votes from the other players leaves the game, the remaining players receive or lose gold. If the players have not chosen anyone by majority vote, none of the players will be executed.
Ivan Tsarevich
Ivan Tsarevich - Originally an anonymous protector of civilians. At night, he checks the roles of other players, as he knows only one of his ally - the Gray Wolf. With the direct participation of the Gray Wolf (who can also check the roles of other players), Ivan Tsarevich, instead of checking, can kill another character at night. If, as a result of the check, Ivan Tsarevich sees the role of the Good Fellow or Red Maiden in the player, then he can invite them to his place and introduce them to the Gray Wolf and other Good Fellows and Red Maidens. Ivan can be hindered by the Frog Princess, who can seduce him at night, while not betraying his role to other players during the day. If Ivan himself discovers the Frog Princess, he can offer her to join the civilians, but if the Princess refuses, she dies at the hands of Ivan. The Gorynych Serpent can also interfere with Ivan Tsarevich's checks, but, unlike the Frog Princess, during the day he will tell the other players which of them is Ivan Tsarevich. During the day, Ivan Tsarevich is no different from other Good Fellows.
Gray wolf
Gray wolf - Assistant to Ivan Tsarevich, whose keen sense of smell helps Ivan to find other Good Fellows and Red Maidens. The Gray Wolf tells these players who Ivan Tsarevich is, and also informs about other players with the roles of Good Fellows and Red Maidens. If the Wolf discovers a robber or other enemy, he immediately informs Ivan Tsarevich about this so that he takes action the next night. If the Wolf is attacked by the Frog Princess, he turns into an ordinary Good Guy and cannot check on anyone, and the Princess will not know that it was actually the Gray Wolf, since the Wolf does not sleep at night. However, the Wolf himself, at the same time, finds out during the day which of the players is the Frog Princess, and can try to persuade the rest of the Good Fellows and the Red Maidens, whom he brought to Ivan Tsarevich, to vote for the execution of the Frog Princess. Also, the next night, she can try to anonymously persuade the Frog Princess to the side of civilians so that she does not touch any of them. The wolf can sacrifice himself at night to save Ivan Tsarevich or Vasilisa the Wise, if he assumes that they suddenly fall under the blow of robbers, or were zombified by Koshchei (the Wolf has an innate immunity to Koshchei's charms), but the Wolf after self-sacrifice is eliminated from the game.
Vasilisa the Wise
Vasilisa the Wise - plays for civilians, but they do not know about her, since Vasilisa is very modest. Also, Vasilisa the Wise, when he heals, does not ask questions and, like a good doctor, treats everyone. But if Koschey, Likho or Goblin drink her medicine, they will not live longer than one day, since Vasilisa only heals people. The medicines of Vasilisa the Wise will not help the Serpent Gorynych or the Cat-Bayun either, but they will not bring harm either. Also, Kot-Bayun does not touch Vasilisa at night, since Vasilisa does not go to the Lifeless Forest for medicinal herbs. In addition, the female charms of the Frog Princess do not work on Vasilisa. If her patient is tried to be killed twice, medicine will be powerless. Vasilisa will not save you from magical attacks, for example, from the curse of Leah. During the day, Vasilisa behaves like a Red Maiden, and only a fleeting, slightly sad look can give a little hint that she is the best doctor in Far Far Away.
Rogue
Rogues, unlike all previous roles, they know each other, because they live in the same Lair, and they also know Leshy and Baba Yaga, so they can act in concert right from the first move. But only the Leader of the gang performs actions at night and does not vote during the day, while the rest of the Robbers diligently pretend to be Good Fellows and Red Maidens. If the Leader is removed from the game for any reason, one of the remaining Rogues immediately takes his place. First of all, the Robbers try to disable Ivan Tsarevich until he has gathered enough forces from the Good Fellows and the Red Maidens to actively resist the Robbers during the day.
Leshy
Leshy spies for the Rogues at night, informing them of the roles he has found in their Lair, but does not vote during the day, as he does not live in the village. However, other players can vote for Leshy and thus execute him. Since Leshy comes from swamps, the Frog Princess cannot seduce him, and if she tries, Leshy will mark her house, and the villagers will find out who she really is. Leshy should not be afraid of the spell of Koshchei, but Vasilisa can heal him to death. If Cat-Bayun tries to attack Leshy, he risks losing his iron claws, and then the Cat will have to put the victims to sleep with just purring.
Baba Yaga
Baba Yaga also works together with the Robbers, conjures at night: he can either send a disease to other players, or protect one of the allies from attack. Her sorcery is even stronger than Leah's curse. During the day, Baba Yaga is also active: the one who is under her protection cannot be executed even by a majority vote. However, the supply of magic roots for daytime protection is limited, so Baba Yaga cannot protect anyone, including herself, more than three times per game. At the same time, during the day, Baba Yaga pretends to be an ordinary Red Maiden and votes with everyone together.
Dragon
Dragon at night it flies over villages, forests and swamps and is engaged in robbery, revealing the role of the robbed during the day. During the day, the Serpent sleeps, so he does not vote, but he can be executed by a majority vote. The snake is very dangerous for everyone, especially for the Robbers and Ivan Tsarevich. The snake does not care who to rob, but if the Wolf or Leshy opens it, he can become a valuable ally. If you kill the Serpent at night, you can, with some probability, get a very valuable item - the Serpent Skin, which will protect its owner from a physical attack once.
Famously one-eyed
Famously one-eyed at night he kills everyone who gets in his way, and whom he cannot kill (Leshy, Kota-Bayun, or the Serpent Gorynych) - he curses, so that anyone who tries to communicate with the damned that same night will die during the day. At the same time, the damned one also dies, only Kot-Bayun does not die, who simply goes to bed to gain strength, skipping the next night. Only Baba Yaga can save from Likha's curse. The curse does not affect the one who defeated the Cat-Bayun: he, like the Cat, simply goes to bed with a pass.
Princess Frog
Princess Frog cannot win the game, but can earn a lot of money by seducing other players at night. The tempted one misses a turn. The frog cannot seduce Vasilisa the Wise, and she should also avoid Leshy, who will hand her over to everyone the next day. If Ivan Tsarevich or the Leader of the Robbers find the Frog, they can invite civilians or the Robbers to the side, while Ivan does not accept the Frog's refusal, but the Leader is not so picky. But the Princess is quite cunning, she can become a double agent, because despite the fact that she alone cannot win, this is a great chance to score gold, because the chances of making it to the end of the game greatly increase! During the day, the Frog Princess pretends to be the Red Maiden and votes with everyone together.
Koschei the Deathless
Koschei the Deathless lives in a castle. At night, he walks around the surrounding villages and zombifies the Good Fellows and the Red Maidens, who go to his service and unquestioningly carry out all orders. Refusing to comply with the order, for example, to vote during the day differently than what was said by Koshchei, or write messages in the chat during the day, if Koshchei forbade it, Koshchei's Servant dies. Thus, Koschey is able to influence the results of voting during the day, even though he does not personally vote. If Koshchei is killed, all of his victims also die. Vasilisa can heal Koshchei's Servant, who then returns to his original role. The Serpent-Gorynych and the Wolf have innate immunity to zombies, so Koschei, with all his desire, cannot turn them into his service. Also, the Wolf can help Ivan or Vasilisa out of trouble by sacrificing himself. Those rescued by the Wolf gain Wolf immunity to zombification.
Cat Baiyun
Cat Baiyun lives in the forest, hunts at night. During the day he sleeps in his hollow, so he does not participate in the voting. However, during the day he can be executed by a majority vote. The cat can attack in two ways: purr - and then his victim falls asleep and cannot walk at night, and also vote the next day - or kill immediately with iron claws. The claw attack does not work on the Serpent-Gorynych, and, having attacked Leshy, the Cat may be left without claws at all! Likho cannot curse the Cat, who, after the curse, will simply sleep for one night. If someone overpowers Kota-Bayun to win, he will be healed of any disease and illness, including the curse of Leah. This Kotova ability remains with the player until the end of the game. Koshchei's servants cannot vote for Kot during the day, but they can indirectly find out who Koshchei is without informing Koshchei about it. Kot-Baiyun does not enter into alliances with Ivan or Rogues, so they are a primary target for Kot.
Technologies used
To write the game, I chose serverless computing (serverless) technology based on OpenFaaS, because it is simple enough to organize a game, and at the same time advanced enough to write complex game rules without too much complexity. I will also use a Kubernetes cluster, since this method of deploying applications makes it quite simple and reliable to get fast deployment, easy scaling. To create game logic, you can only use OpenFaaS, but I will also try to make the Storyteller as a separate container to compare the implementation complexity. As the main programming language for microservices and functions, I chose
Announcement
- Introduction
- Setting up a development environment, splitting a task into functions
- Backend work
- Frontend work
- CICD setup, testing organization
- Starting a trial game session
- Results
Source: habr.com