当前位置: 首页 > 软件库 > 游戏/娱乐 > >

tictac

授权协议 Readme
开发语言 C/C++
所属分类 游戏/娱乐
软件类型 开源软件
地区 不详
投 递 者 闾丘德宇
操作系统 未知
开源组织
适用人群 未知
 软件概览

Tictac

This is a demonstration of building a clustered, distributed, multi-player, turn-based game server written in Elixir. As designed, it plays Tic-Tac-Toe, but was designed to be extended to play almost any multi-player turn based game.

This uses Phoenix LiveView for the UI, TailwindCSS for styles, libcluster for clustering the nodes, horde for providing a distributed process registry, and fly.io for hosting and multi-region clustering support.

You can read the blog post about it here: fly.io/blog/building-a-distributed-turn-based-game-system-in-elixir/

Try it out locally

To try the project out locally:

  • Install dependencies with mix deps.get
  • Install Node.js dependencies with npm install inside the assets directory
  • Start Phoenix endpoint with mix phx.server

Now you can visit localhost:4000 from your browser.

Since ths is multi-player, open a second browser window to the same address. localhost:4000

This is what a game looks like:

Running it multi-node and clustered

To run it clustered locally, in a terminal window, run the following command:

PORT=4000 iex --name a@127.0.0.1 --cookie asdf -S mix phx.server

In a separate terminal window, run this command:

PORT=4001 iex --name b@127.0.0.1 --cookie asdf -S mix phx.server

Now in one browser window, visit localhost:4000.

From another browser window, visit localhost:4001.

You created two clients that are connected to two separate Elixir nodes which are clustered together! This is what it looks like where "ABCD" is a started game.

Deploying it to Fly.io

Deploy this to your own Fly.io account and see it in action for yourself!

  • Setup your Fly.io account
  • Clone this repo
  • Register your app on Fly.io
fly launch --name my-special-custom-name
  • Take all the defaults. As for the region, choose sea (Seattle, Washington (US))
  • Replace the generated fly.toml file with the following config but keep the app name that you chose for your app.
app = "<my-special-custom-name>"

kill_signal = "SIGTERM"
kill_timeout = 5

[[services]]
  internal_port = 4000
  protocol = "tcp"

  [services.concurrency]
    hard_limit = 25
    soft_limit = 20

  [[services.ports]]
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.tcp_checks]]
    grace_period = "30s" # allow some time for startup
    interval = "15s"
    restart_limit = 6
    timeout = "2s"
  • Setup your Phoenix secrets
$ mix phx.gen.secret
gZNW554LeBx4VGuG2U+X3fe7OCmk28g3OIE0Ia+OFRxS7+bhEm/2ZnIvnGTRo4DO

$ fly secrets set SECRET_KEY_BASE=gZNW554LeBx4VGuG2U+X3fe7OCmk28g3OIE0Ia+OFRxS7+bhEm/2ZnIvnGTRo4DO
Secrets are staged for the first deployment
  • Deploy!
fly deploy
  • Open it in the browser
fly open

At this point you have a working system. This is where most systems stop!

Take it Multi-Region!

Ready to take it to multiple regions? We've got one in Seattle on the West Coast, let's add one on the East Coast to cover the whole US.

  • Add a region ewr (Parsippany, NJ (US))
fly regions add ewr
  • Scale it up
fly scale count 2
  • Check the Status - Re-run this command to see it balance out
fly status
  • Check out the logs
fly logs

2021-03-31T14:28:22.880Z c9b72c04 sea [info] [info] [libcluster:fly6pn] connected to :"tictac@fdaa:0:1da8:a7b:ab3:1c48:eb59:2"
2021-03-31T14:28:22.881Z c9b72c04 sea [info] [info] Starting Horde.RegistryImpl with name Tictac.GameRegistry
2021-03-31T14:28:22.884Z c9b72c04 sea [info] [info] Starting Horde.DynamicSupervisorImpl with name Tictac.DistributedSupervisor
2021-03-31T14:28:22.890Z c9b72c04 sea [info] [info] Running TictacWeb.Endpoint with cowboy 2.8.0 at :::4000 (http)
2021-03-31T14:28:22.892Z c9b72c04 sea [info] [info] Access TictacWeb.Endpoint at https://tictac.fly.dev

The first log line shows the nodes are connected.

You now have a clustered Elixir application where users connect to the nearest server for them. This can provide a better user experience!

What will you build?

Tic-Tac-Toe is a simple game. This architecture could support any multi-player turn-based game you might think of. What cool game do you want to make?

Livebook notebooks!

I used Livebook notebooks to document the app logic in a regular Phoenix Web application! I created two notebooks to document how the game state works and also how a game server runs that state.

They are just plain markdown files as far as the project is concerned. Open them with Livebook and follow this guide to execute them in the context of the application.

You will find them in the notebook folder.

  • 博主不定期更新【保研/推免、C/C++、5G移动通信、Linux、生活随笔】系列文章,喜欢的朋友【点赞+关注】支持一下吧! tic-tac-toe游戏   读入一个3×3矩阵,矩阵中的数字为1表示该位置上有一个X,为0表示该位置上有一个O,要求编写程序判断这个矩阵中是否有获胜的一方,输出表示获胜一方的字符X或O,或输出无人获胜。   本游戏获胜是指在同一行、同一列或同一对角线上,有三个相同字符。

  • 题目描述: 你玩过井字棋游戏吗?它的英文名字叫做tic-tac-toe,是一个古老的博弈游戏。游戏在一 个3 £ 3的棋盘上进行。游戏约定,先在同一条线(横线、纵线或斜线)上占有3枚棋子者得 胜。尽管现在借助计算机可以生成这个游戏所有可能的情况,但这个古老的游戏从未失去它 在博弈游戏中的意义。在它的身上不断可以看到有新的东西产生。比如,有人将井字棋游戏 从平面空间扩展到三维空间,发明了立体井字棋。

  • tictac 立体井字棋 源文件名:tictac.(pas/c/cpp) 输入文件:tictac.in 输出文件:tictac.out 时间限制:1秒 空间限制:64M 问题描述   你玩过井字棋游戏吗?它的英文名字叫做tic-tac-toe,是一个古老的博弈游戏。游戏在一个3×3的棋盘上进行。游戏约定,先在同一条线(横线、纵线或斜线)上占有3枚棋子者得胜。尽管现在借助计算机可以生成这个游戏所有可

 相关资料
  • 我被要求将我的玩家与玩家的打球游戏改进为玩家与电脑对抗的AI打球游戏:为此,我需要编写两个函数:一个获取棋盘和当前玩家的符号,并返回所有可能的未来棋盘列表-每个未来棋盘都是一个包含两个元素的列表:一个是放置符号的位置另一个是放置符号后的板-一圈后的板(我使用的是嵌套的列表板,如下面的代码所示(我在这里收到了帮助) 我需要的第二个函数是计算机转动的函数——它使用第一个函数并通过以下方式之一选择最佳移

  • 我是Java的新手,我正在尝试构建一个简单的TicTactoE-game。我创建了checkforWin方法来检查棋盘上不同组合的胜者,它似乎很管用,但似乎很麻烦,我不确定它是否被认为是“好的编码”。这是我的代码: 问题是将checkforWin方法拆分为两个方法是否更好,一个用于播放机,一个用于计算机。此外,我不知道使用和if-else语句来检查板子上的对角线胜利是否是个好主意,开始两个检查中心

  • 我是Java的新手,我正在尝试构建一个简单的TicTactoE-game。我创建了checkforWin方法来检查棋盘上不同组合的胜者,它似乎很管用,但似乎很麻烦,我不确定它是否被认为是“好的编码”。这是我的代码: 问题是将checkforWin方法拆分为两个方法是否更好,一个用于播放机,一个用于计算机。此外,我不知道使用和if-else语句来检查板子上的对角线胜利是否是个好主意,开始两个检查中心

  • 我需要创建一个方法来检查tictactoe游戏是否在玩、DRAW、XWIN或owin。然而,我很难编写代码来检查X或O是否获胜,因为游戏板的大小和获胜所需的大小(sizeWin)会根据用户的输入而改变。我被迫使用一维阵列的游戏板。我根本不知道从这里到哪里去。我最近的想法是使用嵌套的for循环来检查是否按行、列或对角线获得胜利,但我不确定如何实现它。如果有人对如何处理这个问题有任何提示,或者有任何其

  • 我被我的tictactoe问题困住了。定义一个称为TicTacToe的calss。TicTacToe类型的对象是TicTacToe的单个游戏。将游戏板存储为一个具有三行三列的基类型char的单个2D数组。包括添加移动、显示棋盘、判断轮到谁、判断是否有胜者、判断谁是胜者以及重新开始游戏的方法。为类编写一个主方法,允许两个玩家在同一键盘上依次输入他们的动作。 我写了一些我的方法,并一直在测试我去。当我

  • 我目前正在工作的一个分配的项目,以创造一个抽搐tac脚趾游戏在Java。这是我到目前为止,所有的代码工作相当好,游戏和它的功能工作非常好。我应该记录X胜、O胜和平局;然而,这似乎是问题所在。由于某种原因,即使我指定了计算机模拟的tic tac toe游戏应该有1000次迭代,x胜、o胜和平局加起来从来不是1000。它总是一个非常接近1000的数字,但我不知道为什么它总是变化。下面是我在main类中

  • 当我编译时,我得到了这个错误:TicTacToe.java:110:error:TicTacToe类中的方法addMove不能应用于给定的类型;if(addMove()){^required:int,int found:无参数原因:实际和正式参数列表长度不同1错误 我怎么才能修好这个?