git clone ssh://git@59.175.109.42:23022/Alice/snakeunknownbattlegrounds.git
git checkout tradition
./demo.bash
tradition solution's main module( contains new features under developing )
you can see some useful examples here
contains a padding function to pad all view input to 9x9
provide easy way to control snake
control of class takeActionimport socket
from takeAction import takeAction
sk = socket.socket()
host = socket.gethostname()
port = 8888
sk.connect((host, port))
control=takeAction(sk)
control.getView()# the view is stored in control.view
control.goRight()# go right
control.getView()# get view
control.goDown()# go down
control.getView()# get view
update:10.20
isNormal=control.normal#normal:True slipper:False
update:10.21
time=control.time
display map in a visible way
takeAction above, you can access the map byprint(control.map.map)
print(control.map.partMap)
the partMap will change dynamically to adjust to the size hardwritten in the defination of class Map
class Map():
def __init__(self):
# 修改这里:改变打印显示地图的大小
baseMap=-2*np.ones([15,10], dtype = int)
……
you can change the size of baseMap to change the display size of partMap,but the data of the whole map is stored in map permanently with size allocated dynamically
TODO: a function to display whole map, use keyboard to go sightseeing
main idea is to find the edge of the map, but the map is so broad that other corners is still unreached **but there is a set of functions to tour around the map **
- towardDirection: go toward one direction based on member varible `self.direction`
- chooseDirection: decide which direction to go according to the score of each direction
- calculateScore: calculate the score of each direction according to the global variable `possibleTypes` in `findEdge.py`
go along with the direction of downright, once a step
a. have an instance of takeAction above like control in this example
control=takeAction(sk) #sk need to connect to the right port
b. then execute it in a loop to reach the final situation(dead way etc)
while(1):
findEdge(control)
update:10.21
handy to let snake go around with the input line
a. have an instance of takeAction above like control in this example, and an instance of generatePath above like path in this example
control=takeAction(sk)
path=generatePath(control)
b. then write a list of direction like:
line=[direction.right,direction.right,direction.down,
direction.left,direction.left,direction.up]
hint: you may need to import `direction` from `findEdge.py`
from findEdge import generatePath,direction,findEdge,goThrough
c. execute
goThrough(path,control,line)
update:10.21
explore in a limited range to inspect the growth rule of poison thorn
the function is based on goThrough(path,control,line) above, just print verbose information
本文章使用limfx的vscode插件快速发布