我是NuSMV的新手,並嘗試對這個簡單的回合制遊戲進行建模。一堆中有10塊磚,每個玩家每回合可以拿1-3塊磚,誰拿走最後一塊磚就贏得比賽。假設玩家A先去,這是我的嘗試。我想表達的是,「最終有一個勝利者」,但是我的代碼不起作用,因爲它不阻止玩家在磚塊= 0之後採取磚塊,所以最終玩家a,b都會成爲贏家。NuSMV模型檢查:創建一個簡單的遊戲模型
這裏是我的代碼:
MODULE main
VAR
bricks : 0..10;
i : 1..3;
j : 1..3;
turn : boolean;
winner : {none, a, b};
ASSIGN
init(winner) := none;
init(bricks) := 10;
init(turn) := TRUE;
next(turn) := case
turn : FALSE;
!turn: TRUE;
esac;
next(bricks) :=
case
bricks - j >= 0 : bricks - j;
bricks - j < 0 : 0;
TRUE:bricks;
esac;
next(winner) := case
turn=TRUE & bricks = 0: a;
turn=FALSE & bricks = 0: b;
TRUE:winner;
esac;
SPEC AF (winner = a | winner = b)
,這裏是我的SPEC AF(冠軍= A | =得主無)輸出到說明我的觀點。
i = 1
j = 1
turn = TRUE
winner = none
State: 1.2 <-
bricks = 9
j = 3
turn = FALSE
State: 1.3 <-
bricks = 6
turn = TRUE
State: 1.4 <-
bricks = 3
turn = FALSE
State: 1.5 <-
bricks = 0
j = 1
turn = TRUE
State: 1.6 <-
turn = FALSE
winner = a
State: 1.7 <-
turn = TRUE
winner = b
正如你所看到的,模型仍然提供了一個反例的例子,其中玩家b已經贏得比賽後贏得比賽。