资源简介
GOWOG是一款用Golang编写的多人网页游戏。 感谢Golang,服务器可以同时处理大量玩家。
代码片段和文件信息
“““
AI Environment for CS2D following OPEN AI Environment style:
env.step((x y)): Move the agent (x y).
env.reset(): Reset the environment and return the observartion in formatted 1D array.
env.observation_space.shape: Return the shape of observation.
env.action_space.n: Return the shape of action
“““
from websocket import create_connection
import random
import math
import message_pb2 as messagepb
import numpy as np
LOCAL_ENV = ‘local‘
MAX_STEPS = 200
Player_SIZE = 32
BLOCK_SIZE = 64
EPS = 5
WIN_REWARD = 30 # = 1 / distance to the nearest point = 1/ 2
GOAL = {“x“: BLOCK_SIZE * 11 “y“: BLOCK_SIZE * 5}
dx = [-1 0 1 0]
dy = [0 -1 0 1]
class ObservationSpace:
def __init__(self shape):
self.shape = shape
class ActionSpace:
def __init__(self shape):
self.n = 4
self.sample = random.randint(0 self.n)
class CS2DEnvironment:
def __init__(self env name):
if env == LOCAL_ENV:
wshost = ‘ws://localhost:8080/game/‘
else:
wshost = ‘ws://game.giongto35.com/game/‘ # Not allowed yet
self.name = name
self.wshost = wshost
self.init()
self.observation_space = ObservationSpace(self.get_obs_size())
self.action_space = ActionSpace(4)
def step(self d):
“““
Return observation reward done None
Move agent in the direction of d[0] d[1]
“““
dx dy = d[0] d[1]
obs reward done = self.move_position(dx dy)
return obs reward done None
def set_position(self x y):
# Construct set_position message
message = messagepb.ClientGameMessage()
set_position = messagepb.SetPosition()
set_position.id = self.player.id
set_position.x = x
set_position.y = y
message.set_position_payload.CopyFrom(set_position)
message.input_sequence_number = self.current_input_number
self.ws.send(message.SerializeToString())
# Update agent position also
self.player.x = x
self.player.y = y
def move_position(self dx dy):
“““
Move position toward (dx dy)
“““
self.num_steps += 1
self.current_input_number += 1
message = messagepb.ClientGameMessage()
# construct message
message.time_elapsed = 0.1
move_position = messagepb.MovePosition()
move_position.id = self.player.id
move_position.dx = dx
move_position.dy = dy
message.move_position_payload.CopyFrom(move_position)
message.input_sequence_number = self.current_input_number
self.ws.send(message.SerializeToString())
# The for loop to receive the response from server
while True:
binary_res = self.ws.recv()
# Received client accepted from server with client_id
serverMsg = messagepb.ServerGameMessage()
serverMsg.ParseFromString(binary_res)
# If received
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-05-09 14:55 gowog-master\
文件 31 2019-05-09 14:55 gowog-master\.dockerignore
文件 49 2019-05-09 14:55 gowog-master\.gitattributes
文件 99 2019-05-09 14:55 gowog-master\.gitignore
文件 743 2019-05-09 14:55 gowog-master\Dockerfile
文件 1073 2019-05-09 14:55 gowog-master\LICENSE
文件 5195 2019-05-09 14:55 gowog-master\README.md
目录 0 2019-05-09 14:55 gowog-master\ai\
文件 2691 2019-05-09 14:55 gowog-master\ai\README.md
文件 7888 2019-05-09 14:55 gowog-master\ai\cs2denv.py
文件 10531 2019-05-09 14:55 gowog-master\ai\cs2denv_ga.py
文件 49557 2019-05-09 14:55 gowog-master\ai\message_pb2.py
文件 104 2019-05-09 14:55 gowog-master\ai\requirements.txt
文件 273 2019-05-09 14:55 gowog-master\ai\test_env.py
文件 7224 2019-05-09 14:55 gowog-master\ai\train_ga.py
目录 0 2019-05-09 14:55 gowog-master\client\
文件 8196 2019-05-09 14:55 gowog-master\client\.DS_Store
文件 25 2019-05-09 14:55 gowog-master\client\.babelrc
文件 356 2019-05-09 14:55 gowog-master\client\.eslintrc.json
文件 79 2019-05-09 14:55 gowog-master\client\.gitignore
文件 1083 2019-05-09 14:55 gowog-master\client\LICENSE.md
文件 1945 2019-05-09 14:55 gowog-master\client\README.md
目录 0 2019-05-09 14:55 gowog-master\client\assets\
文件 6148 2019-05-09 14:55 gowog-master\client\assets\.DS_Store
目录 0 2019-05-09 14:55 gowog-master\client\assets\css\
文件 2943 2019-05-09 14:55 gowog-master\client\assets\css\main.css
目录 0 2019-05-09 14:55 gowog-master\client\assets\images\
文件 8196 2019-05-09 14:55 gowog-master\client\assets\images\.DS_Store
文件 910 2019-05-09 14:55 gowog-master\client\assets\images\bullet.png
文件 12332 2019-05-09 14:55 gowog-master\client\assets\images\enemy.png
文件 1049 2019-05-09 14:55 gowog-master\client\assets\images\maptile.png
............此处省略84个文件信息
评论
共有 条评论