Fix: reset cancel list after discard

This commit is contained in:
2020-05-31 14:51:36 +08:00
parent 55d06fefaa
commit 84991d4860
5 changed files with 22 additions and 7 deletions
+7 -4
View File
@@ -1,6 +1,9 @@
package container
import "testing"
import (
"github.com/c-my/MahjongServer/rule"
"testing"
)
func TestGetHall(t *testing.T) {
hall := GetHall()
@@ -15,7 +18,7 @@ func TestGetHall(t *testing.T) {
func TestHall_CreateRoom(t *testing.T) {
hall := GetHall()
roomID := hall.CreateRoom(0001, "ppp")
roomID := hall.CreateRoom(0001, "ppp", rule.NewJinzhouRule())
if roomID == -1 {
t.Errorf("failed to create first room")
}
@@ -23,7 +26,7 @@ func TestHall_CreateRoom(t *testing.T) {
func TestHall_JoinRoom(t *testing.T) {
hall := GetHall()
roomID := hall.CreateRoom(0002, "ppp")
roomID := hall.CreateRoom(0002, "ppp", rule.NewShenyangRule())
if hall.JoinRoom(0003, roomID, "ppp") != Success {
t.Errorf("2nd player joined failed")
}
@@ -43,7 +46,7 @@ func TestHall_JoinRoom(t *testing.T) {
func TestHall_GetRoomID(t *testing.T) {
hall := GetHall()
roomID := hall.CreateRoom(0007, "ppp")
roomID := hall.CreateRoom(0007, "ppp", rule.NewJinzhouRule())
if hall.GetRoomID(7) != roomID {
t.Errorf("get wrong roomID")
}
+2 -1
View File
@@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"github.com/c-my/MahjongServer/container"
"github.com/c-my/MahjongServer/rule"
"log"
"net/http"
"net/http/httptest"
@@ -31,7 +32,7 @@ func TestRoomCreateHandler(t *testing.T) {
}
func TestRoomJoinHandler(t *testing.T) {
roomID := container.GetHall().CreateRoom(003, "pp")
roomID := container.GetHall().CreateRoom(003, "pp", rule.NewJinzhouRule())
body, _ := json.Marshal(joinRoomMsg{
UserID: 004,
RoomID: roomID,
+2 -1
View File
@@ -2,13 +2,14 @@ package controller
import (
"github.com/c-my/MahjongServer/container"
"github.com/c-my/MahjongServer/rule"
"github.com/gorilla/websocket"
"net/url"
"testing"
)
func TestWsHandler(t *testing.T) {
container.GetHall().CreateRoom(100, "100")
container.GetHall().CreateRoom(100, "100", rule.NewJinzhouRule())
u := url.URL{Scheme: "ws", Host: "127.0.0.1:1114", Path: "/100"}
_, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
if err == nil {
+1
View File
@@ -158,6 +158,7 @@ func (m *MahjongManager) Draw(hand []model.Tile, shown []model.ShownTile, newTil
func (m *MahjongManager) handleDiscard(msg message.GameMsgRecv, isJustCanceled bool) {
currentOrder := msg.TableOrder
m.lastTableOrder = msg.TableOrder
m.resetCancelList()
lastAct := config.Cancel
if !isJustCanceled { //从手牌中删除
lastAct = config.Discard
+10 -1
View File
@@ -111,6 +111,14 @@ func TestJinzhouRule_CanWin(t *testing.T) {
[]model.ShownTile{{config.ConcealedKong, []model.Tile{{0, 3}, {0, 3}, {0, 3}, {0, 3}}}},
model.Tile{2, 6},
false}, //缺门
{[]model.Tile{{0, 1}, {0, 1},
{0, 4}, {0, 4}, {0, 4},
{0, 6}, {0, 8},
{1, 5}, {1, 6}, {1, 7},
{2,9},{2,9},{2,9}},
[]model.ShownTile{},
model.Tile{0, 7},
true},
}
for _, test := range tests {
if j.CanWin(test.hand, test.shown, test.newTile) != test.want {
@@ -166,7 +174,8 @@ func BenchmarkJinzhouRule_CanWin_LackDoor(b *testing.B) {
{2, 1}, {2, 2}, {2, 3}, {2, 7}, {2, 8}, {2, 9}, {2, 9}},
[]model.ShownTile{{config.ConcealedKong, []model.Tile{{0, 3}, {0, 3}, {0, 3}, {0, 3}}}},
model.Tile{2, 6},
false} //缺门
false,
} //缺门
b.ResetTimer()
for i := 0; i < b.N; i++ {
j.CanWin(test.hand, test.shown, test.newTile)