Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ChatGPT prompt: write a python streamlit program that creates a dungeon crawler game featuring a reinforcement learning monster that a player can fight and slay
|
2 |
+
|
3 |
+
import streamlit as st
|
4 |
+
|
5 |
+
import random
|
6 |
+
|
7 |
+
import numpy as np
|
8 |
+
|
9 |
+
# create a class for the monster
|
10 |
+
class Monster():
|
11 |
+
def __init__(self, name, hp, attack, defense):
|
12 |
+
self.name = name
|
13 |
+
self.hp = hp
|
14 |
+
self.attack = attack
|
15 |
+
self.defense = defense
|
16 |
+
|
17 |
+
# create a class for the player
|
18 |
+
class Player():
|
19 |
+
def __init__(self, name, hp, attack, defense):
|
20 |
+
self.name = name
|
21 |
+
self.hp = hp
|
22 |
+
self.attack = attack
|
23 |
+
self.defense = defense
|
24 |
+
|
25 |
+
# create the reinforcement learning monster
|
26 |
+
class ReinforcementMonster():
|
27 |
+
def __init__(self, name, hp, attack, defense):
|
28 |
+
self.name = name
|
29 |
+
self.hp = hp
|
30 |
+
self.attack = attack
|
31 |
+
self.defense = defense
|
32 |
+
|
33 |
+
# create a function to generate a random number
|
34 |
+
def random_number():
|
35 |
+
x = random.randint(1,20)
|
36 |
+
return x
|
37 |
+
|
38 |
+
# create a function to start the game
|
39 |
+
def start_game():
|
40 |
+
# create a monster
|
41 |
+
monster = Monster('goblin',100,20,10)
|
42 |
+
# create a player
|
43 |
+
player = Player('hero',100,20,10)
|
44 |
+
# create a reinforcement monster
|
45 |
+
reinforcement_monster = ReinforcementMonster('dragon',100,30,15)
|
46 |
+
|
47 |
+
# create a loop to simulate a battle
|
48 |
+
while monster.hp > 0 and player.hp > 0:
|
49 |
+
# player attack monster
|
50 |
+
monster.hp = monster.hp - player.attack
|
51 |
+
print(f'Player {player.name} attacks {monster.name} with {player.attack}')
|
52 |
+
print(f'{monster.name} has {monster.hp} hp left')
|
53 |
+
# monster attack player
|
54 |
+
if monster.hp > 0:
|
55 |
+
player.hp = player.hp - monster.attack
|
56 |
+
print(f'{monster.name} attacks {player.name} with {monster.attack}')
|
57 |
+
print(f'{player.name} has {player.hp} hp left')
|
58 |
+
|
59 |
+
# check if player won the fight
|
60 |
+
if player.hp > 0:
|
61 |
+
print(f'{player.name} has defeated {monster.name}!')
|
62 |
+
|
63 |
+
# reinforcement monster attack
|
64 |
+
reinforcement_monster.hp = reinforcement_monster.hp - player.attack
|
65 |
+
print(f'Player {player.name} attacks {reinforcement_monster.name} with {player.attack}')
|
66 |
+
print(f'{reinforcement_monster.name} has {reinforcement_monster.hp} hp left')
|
67 |
+
# reinforcement monster attack player
|
68 |
+
if reinforcement_monster.hp > 0:
|
69 |
+
player.hp = player.hp - reinforcement_monster.attack
|
70 |
+
print(f'{reinforcement_monster.name} attacks {player.name} with {reinforcement_monster.attack}')
|
71 |
+
print(f'{player.name} has {player.hp} hp left')
|
72 |
+
|
73 |
+
# check if player won the fight
|
74 |
+
if player.hp > 0:
|
75 |
+
print(f'{player.name} has defeated {reinforcement_monster.name}!')
|
76 |
+
print('You have won the game! Congratulations!')
|
77 |
+
|
78 |
+
# create a main function
|
79 |
+
def main():
|
80 |
+
st.title('Dungeon Crawler with Reinforcement Learning Monster')
|
81 |
+
|
82 |
+
# create a start button
|
83 |
+
if st.button('Start'):
|
84 |
+
start_game()
|
85 |
+
|
86 |
+
if __name__ == '__main__':
|
87 |
+
main()
|