-
Notifications
You must be signed in to change notification settings - Fork 0
/
manual.py
116 lines (95 loc) · 2.84 KB
/
manual.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import numpy as np
import copy
import sys
from nanoRTS.nanoRTS import nanoRTS, nanoROOMS
import pygame
from pygame.locals import *
DEFAULT_FILE = "./scenarios/2_forts_2Av3K.json"
def main():
if len(sys.argv) == 1:
scenario = DEFAULT_FILE
else:
scenario = sys.argv[1]
if "room" in scenario:
env = nanoROOMS(scenario, visual=True, graphics=True, textures="./textures")
actions = {
"U": [0, -1],
"R": [1, 0],
"D": [0, 1],
"L": [-1, 0]
}
elif "simple" in scenario:
env = nanoRTS(scenario, visual=True, graphics=True, textures="./textures")
if "W" in scenario:
actions = {
"U": [0, -1],
"R": [1, 0],
"D": [0, 1],
"L": [-1, 0],
"A": "Attack"
}
else:
actions = {
"DR": [1, 1],
"R": [1, 0],
"RR": [2, 0],
"UR": [1, -1],
"D": [0, 1],
"DD": [0, 2],
"DL": [-1, 1],
"L": [-1, 0],
"LL": [-2, 0],
"UL": [-1, -1],
"U": [0, -1],
"UU": [0, -2],
"A": "Attack"
}
elif "2_forts" in scenario:
env = nanoRTS(scenario, visual=True, graphics=True, textures="./textures")
actions = {
"DR": [1, 1],
"R": [1, 0],
"RR": [2, 0],
"UR": [1, -1],
"D": [0, 1],
"DD": [0, 2],
"DL": [-1, 1],
"L": [-1, 0],
"LL": [-2, 0],
"UL": [-1, -1],
"U": [0, -1],
"UU": [0, -2],
"A": "Attack"
}
# elif "custom_map" in scenario:
# env = nanoCUSTOM(scenario, visual=True, graphics=True, textures="./textures")
# actions = {}
# так можно тестировать новые кастомные сценарии
else:
print("Проблема со сценарием", scenario)
return
env.reset()
total = 0
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
a = input("Введите действия: ").split()
acts = list()
for act in a:
if act in actions:
acts.append(actions[act])
continue
if act.upper() in actions:
acts.append(actions[act.upper()])
continue
_, r, t, _ = env.update(acts)
print("Награда за ход", r)
total += r
if t:
break
print("Игра закончена!")
print("Ваш счет: {}".format(total))
if __name__ == "__main__":
main()