Reset premoves when player moves are rejected

This commit is contained in:
Trevor Slocum 2021-11-11 20:28:38 -08:00
parent 18c4cdbc32
commit 16c24d4793
2 changed files with 6 additions and 15 deletions

View File

@ -633,21 +633,16 @@ CHECKPREMOVES:
checkSpace := 0
for _, space := range moves[i] {
checkSpace += space
lf("CHECK %d %d", checkSpace, from+(checkSpace*b.v[StateDirection]))
if !b.spaceAvailable(from + (checkSpace * b.v[StateDirection])) {
continue CHECKPREMOVES
}
}
lf("SECOND PHASE %+v %d", moves[i], num)
if (from+(checkSpace*b.v[StateDirection]) == to) && len(moves[i]) > 1 {
lf("SECOND.5 PHASE %+v %d", moves[i], num)
for j := 0; j < num; j++ {
checkSpace = 0
lastSpace := 0
for _, space := range moves[i] {
checkSpace += space
lf("THIRD PHASE %d %d", from+(lastSpace*b.v[StateDirection]), from+(checkSpace*b.v[StateDirection]))
if !b.addPreMove(from+(lastSpace*b.v[StateDirection]), from+(checkSpace*b.v[StateDirection]), 1) {
return false
}
@ -667,7 +662,6 @@ CHECKPREMOVES:
b.Premovefrom[from]++
b.Premoveto[to]++
}
lf("ADD %+v", b.premove)
return true
}
@ -675,7 +669,6 @@ func (b *Board) AddPreMove(from int, to int) bool {
if !b.addPreMove(from, to, b.selectedNum) {
return false
}
lf("FINAL %+v", b.premove)
b.resetSelection()
b.autoSendMoves()

View File

@ -523,7 +523,6 @@ func (c *Client) eventLoop() {
var movesRegexp = regexp.MustCompile(`^(\w+) moves (.*)`)
var rollsRegexp = regexp.MustCompile(`^(\w+) rolls? (.*)`)
var logInOutRegexp = regexp.MustCompile(`^\w+ logs [In|Out]\.`)
var dropsConnection = regexp.MustCompile(`^\w+ drops connection\.`)
var startMatchRegexp = regexp.MustCompile(`^\w+ and \w+ start a .*`)
var winsMatchRegexp = regexp.MustCompile(`^\w+ wins a [0-9]+ point match against .*`)
var winsThisMatchRegexp = regexp.MustCompile(`^\w+ wins the [0-9]+ point match .*`)
@ -533,7 +532,8 @@ func (c *Client) eventLoop() {
var gameBufferRegexp = regexp.MustCompile(`^\w+ (makes|roll|rolls|rolled|move|moves) .*`)
var pleaseMoveRegexp = regexp.MustCompile(`^Please move ([0-9]) pieces?.`)
var cantMoveRegexp = regexp.MustCompile(`^(\w+) can't move.`)
var invalidMoveRegexp = regexp.MustCompile(`^\*\* You can't move .*`)
var cantMoveRegexp = regexp.MustCompile(`^(\w+) can't move\.`)
var doublesRegexp = regexp.MustCompile(`^\w+ doubles.`)
var acceptDoubleRegexp = regexp.MustCompile(`^\w+ accepts the double.`)
@ -592,7 +592,7 @@ func (c *Client) eventLoop() {
continue
} else if bytes.HasPrefix(b, TypeMOTD) {
for _, line := range bytes.Split(c.motd, []byte("\n")) {
l(string(line))
l(strings.ReplaceAll(string(line), "|", " "))
}
if !setBoardStyle {
c.Out <- []byte("set boardstyle 3")
@ -617,9 +617,6 @@ func (c *Client) eventLoop() {
} else if bytes.HasPrefix(b, TypeLogin) || bytes.HasPrefix(b, TypeLogout) {
b = b[2:]
b = b[bytes.IndexByte(b, ' ')+1:]
l(string(b))
// TODO enable showing log In and Out messages
// TODO remove from who
continue
} else if bytes.HasPrefix(b, TypeMsg) {
lf("Received message: %s", b[3:])
@ -717,6 +714,9 @@ func (c *Client) eventLoop() {
if strings.TrimSpace(string(b)) == "It's your turn to roll or double." || strings.TrimSpace(string(b)) == "It's your turn. Please roll or double" {
c.Out <- []byte("roll") // TODO Delay and allow configuring
}
} else if invalidMoveRegexp.Match(b) {
c.Board.ResetPreMoves()
c.Board.Draw()
} else if cantMoveRegexp.Match(b) {
match := cantMoveRegexp.FindSubmatch(b)
@ -751,8 +751,6 @@ func (c *Client) eventLoop() {
}()
} else if logInOutRegexp.Match(b) {
continue
} else if dropsConnection.Match(b) {
continue
} else if startMatchRegexp.Match(b) {
continue
} else if winsThisMatchRegexp.Match(b) {