种子杯初赛解决方案——tradition分支

  • branch:tradition

Clone

git clone ssh://git@59.175.109.42:23022/Alice/snakeunknownbattlegrounds.git

Checkout

git checkout tradition

Run

./demo.bash

Structure

pathPlan.py

tradition solution's main module( contains new features under developing )

            you can see some useful examples here

padding.py

contains a padding function to pad all view input to 9x9

takeAction.py

provide easy way to control snake

  1. pass socket to instantiate an object control of class takeAction
import socket
from takeAction import takeAction

sk = socket.socket()
host = socket.gethostname()
port = 8888
sk.connect((host, port))

control=takeAction(sk)
  1. then control the snake like below
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

  1. add updateState to enable the snake to record the time after wear slipper you can know the state of snake by
isNormal=control.normal#normal:True slipper:False

update:10.21

  1. add time to record current time, and you can access by
time=control.time

updateMap.py

display map in a visible way

  1. when you have an instance of takeAction above, you can access the map by
print(control.map.map)
  1. or to have a better format in terminal window, use
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

findEdge.py

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 **

generatePath()

- 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`

findEdge(control)

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

goThrough(path,control,line)

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

posionPeriod.py

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插件快速发布