Review
In the previous section, we simply called the actions interface to perform a discard operation. However, we know that in the game of Majsoul
, after declaring Riichi, the server will automatically discard the last tile for the player. Therefore, we need to modify the code from the previous section to cancel this action when the player has already declared Riichi.
How to Determine the State
- The gamestate library provides some game states that can help you determine the current status of the game.
Example Code
package main
import (
"github.com/moxcomic/Archer/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())
}
}
- In the
onExecute
function, we check if the game is currently in a Riichi state. If so, and the current operation isE_PlayOperation_Ankan
, the action will be canceled. - Otherwise, we call the
Discard
action interface to perform the discard operation. - Note: Since the
Discard
action interface requires passing in the tile and draw information, we need to retrieve the tile and draw-cut information fromresult.GetResult()[0].GetTile()
andresult.GetResult()[0].GetMoqie()
. - For more information on
gamestate
, refer to gamestate.