Archer

弃牌进阶

回顾

在上一节中, 我们只是简单的调用 actions 接口来进行出牌操作。但是我们知道在 雀魂 游戏中在立直(Riichi)后全程由服务端自动丢弃最后一张牌, 所以我们在上一章节的代码就要改一改, 在自己已经立直的情况下, 取消该动作。

如何判断

  • gamestate 这个库中提供了一些游戏状态可以辅助你进行判断游戏当前的状态

示例代码

go
package main

import (
  "github.com/moxcomic/Archer/internal/platform/actions"
  "github.com/moxcomic/lq"
)

const (
  E_PlayOperation_None           = iota
  E_PlayOperation_Discard
  E_PlayOperation_Chi
  E_PlayOperation_Pon
  E_PlayOperation_Ankan
  E_PlayOperation_Minkan
  E_PlayOperation_Kakan
  E_PlayOperation_RiiChi
  E_PlayOperation_Tsumo
  E_PlayOperation_Ron
  E_PlayOperation_JiuZhongJiuPai
  E_PlayOperation_Babei
  E_PlayOperation_HuanSanZhang
  E_PlayOperation_DingQue
  E_PlayOperation_Reveal
  E_PlayOperation_Unveil
  E_PlayOperation_LockTile
  E_PlayOperation_Revealliqi
)

func onExecute(result *lq.NotifyAIResult, risk []float64, r, m, f, t float64) {
  if result.GetResult()[0].GetType() == E_PlayOperation_Discard {
    if gamestate.Inst().Riichi()[0] {
      if gamestate.Inst().IsOperation(E_PlayOperation_Ankan) {
        actions.NewMajsoulActions().Cancel()
      }

      return
    }

    actions.NewMajsoulActions().Discard(result.GetResult()[0].GetTile(), result.GetResult()[0].GetMoqie())
  }
}
  • 我们在 onExecute 函数中判断游戏当前是否处于立直状态, 如果是立直状态, 并且当前动作是 E_PlayOperation_Ankan, 则取消该动作。
  • 否则, 我们调用 Discard 动作接口来进行出牌操作。
  • 注意: 由于 Discard 动作接口的调用需要传入牌和摸牌信息, 所以我们需要从 result.GetResult()[0].GetTile()result.GetResult()[0].GetMoqie() 中获取牌和摸切信息。
  • gamestate 参考 gamestate