Giter Site home page Giter Site logo

alphattt's Introduction

Alpha Tic Tac Toe Ultimate

About

Alpha Tic Tac Toe Ultimate(下称 AlphaTTT)项目是一个开源的棋类在线对战平台项目。支持人工智能程序(下称AI)和人类同时接入并且对弈,能够提供排名和观战功能。

本项目包括一个使用Yaws框架实现的Web服务器,以及一个使用Erlang语言实现的对战服务框架,对战平台主要使用Erlang语言实现。

Install

本项目依赖YawsErlang。 请根据您的操作系统,下载Yaws1.97以后版本和Erlang的Otp16R以后版本。

请先clone本项目代码到本地。然后在cmd/shell界面执行如下命令

cd src
erl -make

这样就完成了系统的安装和编译。

Config & Run

打开一个命令行终端,进入 ebin 文件夹,

cd ebin

初始化数据库

在window环境下,执行

deploy.bat

在unix/bash环境下,执行

bash deploy.bat

这个脚本用于初始化数据库,仅需执行一遍。

启动对战服务

重新打开一个命令行终端,进入 ebin 文件夹,在window环境下,执行

start_game_server.bat

在unix/bash环境下,执行

bash start_game_server.bat

如果启动服务器时报错如端口冲突,请打开 src/game_sup.erl 进行修改,如下

TcpServer = {tcp_server, {tcp_server, start_link,[8011, player_agent]},
            				permanent,2000,worker,[tcp_server]},

请将默认的8011端口修改称为你服务器的可用端口即可。 修改完毕后,请执行erl -make 重新编译。

启动web服务器

重新打开一个命令行终端,进入 ebin 文件夹,在window环境下,执行

start_web_server.bat

在unix/bash环境下,执行

bash start_web_server.bat

如果启动服务器时报错如端口和IP冲突,请打开 src/ybed.erl 进行修改,如下

SconfList = [{port, 8888},
                 {servername, "alphattt_web_server"},
                 {listen, {127,0,0,1}},
                 {docroot, Docroot}],

其中,port属性为web服务器端口,默认为8888;listen监听IP地址,默认为127.0.0.1。 修改完毕后,请执行erl -make 重新编译。

建立集群

在Web服务器的命令行终端中,输入

net_adm:ping(gameserver@yourhostname).

其中,yourhostname为你记起的主机名,你可以在gameserver的命令行终端的提示符中查看到。

访问主页

一起就绪,请在Web浏览器中访问http://localhost/login.html即可。

Working With Erlang

使用Erlang语言可以非常轻松的接入平台,因为这个平台本身就是适用 erlang 语言编写的。

实现接口

只需要编写一个模块,实现如下接口,

-export([start/0]).
-export([get_move/1, update/2, display/3, notify/2, stop/1]).

update(Pid, GameState) -> tobeimplemented.

display(Pid, GameState, Move) -> tobeimplemented.

get_move(Pid) -> tobeimplemented.

notify(Pid, Info) -> tobeimplemented.
	
stop(Pid) -> tobeimplemented.	

打开一个命令行终端,进入src目录,键入 erl -make 重新编译。

然后,运行如下erlang语句, 适当修改SIP, 端口号和RoomID即可接入对战平台,

SIP = "10.8.39.80",
NickName = "your_registered_name",
{ok, Pid} = player_client:start(NickName, your_implementation, board, SIP, 8011),
player_client:login(Pid, "your_registered_password"),

Rooms = player_client:show_room(Pid),
RoomID = get_empty_room(Rooms),
io:format("enter room ~p~n", [RoomID]),
	
player_client:enter_room(Pid, RoomID),

在哪里注册用户名? 很简单,在前面提供的Web页面上注册就可以了。

Working With Java

运行ErlangBridge节点

打开一个命令行终端,在windows系统,运行

ebin/jerlang.bat

在unix/bash系统,运行

bash ebin/jerlang.bat

编译Java代码

将src/java/src下java代码编译打包称jar文件,注意依赖 erlang/otp安装目录/lib/Jinterface-1.x.x/priv/OtpErlang.jar文件,然后运行即可。

运行

适用Java环境,运行com.zte.alphattt.Boot的main函数。 如下定义,

PlayerClient playerClient = new PlayerClient(new Mcts(), new Board());
	...
playerClient.connect("127.0.0.1", 8011);
playerClient.login("javarobot", "password");
playerClient.enterRoom("javarobot", 6);
扩展

仅需实现com.zte.alphattt.game.Player接口,并在初始化时传入(a步骤中初始化PlayerClient里传入,如默认已经实现的Mcts类), 即可加入人机,机机对战。

棋盘

提供了一个较快速度的com.zte.alphattt.game.Board,供自己训练时参考。

训练

提供训练台com.zte.alphattt.Bench,供平时训练和测试时使用。

Working With Python

编写自己的python机器人

在src/python下增加python对弈算法,接口已经定义好:

from py_robot.pybot_module import PybotModule

class YourRobot(PybotModule):
    def __init__(self, cal_time, board):
        super(YourRobot, self).__init__(cal_time, board)
        self.tree = {}

    def get_move(self, state):
        move = (0, 0, 0, 0)
        msg_time = "== calculate 999 paths using 1.0 seconds =="
        msg_pro = "== probability is 100. 999/999 =="
        return move, msg_time, msg_pro

已提供一个python版本的board程序可供调用。

对战

代码如下:

if __name__ == '__main__':
    from py_robot.board import Board
    from py_robot.client import Client
    
    IP = "10.9.88.20"
    PORT = 8011
    USERNAME = ""
    PASSWORD = ""
    ROOMID = 1

    your_robot = YourRobot(1, Board)
    state = {"state": Board.start()}
    client = Client(IP, PORT, your_robot, state)
    client.play(USERNAME, PASSWORD, ROOMID)

执行后进入对战房间。

Working with C/C++

alphattt's People

Contributors

halyhuang avatar dearbaoba avatar ruoyudai avatar mrpan96 avatar bestshusheng avatar yyw794 avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

mrpan96 yyw794

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.