使用 If-Else 语句在 NetLogo 中打印输赢

Print Win or Lose in NetLogo using If-Else Statement

这是我正在做的模拟的进度。这个模拟有一个玩家列表,每个玩家都有他们分配的分数或分数。我有一个名为游戏的补丁。有三十场比赛。一旦玩家进入游戏(或者如果他们将在模拟中相遇),就会有一个标签显示,"hit" 已经完成。三十场比赛中的每场比赛也都有自己的积分。积分随机生成。

所以我的问题是,如果玩家赢得或未赢得比赛,我将如何在分配时显示?我的条件是,如果玩家的分数大于或等于游戏的分数,那么它应该显示 "You won the game!" 否则 "You lose!" 当玩家和游戏相遇时会发生这种情况。

我会将另一个变量放在我的玩家自己的变量上,以指示它是赢了还是输了。但我的问题是,我一直在尝试根据我想要的条件对移动过程中的 if-else/if 进行编码,但我遇到了困难。我需要帮助或一些关于如何做到这一点的线索。谢谢。

breed [players player]
breed [games game]
globals [namelist pointslist]
players-own[name points] ;;going to add another variable here
games-own[points istaken]

to setup 
  ca
  ask patches [set pcolor black]
  set namelist["Player 1" "Player 2" "Player 3" "Player 4" "Player 5" "Player 6" "Player 7" "Player 8" "Player 9" "Player 10"]
  set pointslist["1" "1" "1" "5" "3" "3" "4" "2" "2" "5"]

  ;;define counter
  let counter 0 ;;0-9

  repeat 10 [
    create-players 1[
  set name item counter namelist
  set points item counter pointslist
  setxy random-xcor random-ycor
  set shape "person"
  pen-down
]
  set counter counter + 1
  ]

  create-games 30[
    set shape "circle"
    setxy random-xcor random-ycor
    set points random 5 + 1 ;
  ]

  reset-ticks
end 

to go
  tick
  ask players[move]
end

;;this is the part where I added my if-else code but i cannot get it
to move
  ask players [
right(random 181) - 90
fd 1
let hw one-of games-here 
if hw != nobody[

  ask hw [set label "hit"]
    ]
  ]

end

你的描述不是很清楚,但我认为这回答了你的问题。 (请参阅最后的 ifelse 声明。)

globals [namelist pointslist]
breed [players player]
players-own[name points] ;;going to add another variable here
breed [games game]
games-own[points istaken]

to setup 
  ca
  ask patches [set pcolor black]
  set namelist["Player 1" "Player 2" "Player 3" "Player 4" "Player 5" "Player 6" "Player 7" "Player 8" "Player 9" "Player 10"]
  set pointslist[1 1 1 5 3 3 4 2 2 5]  ;use numbers, not strings!

  ;;define counter
  let _counter 0 ;;0-9

  create-players 10 [
    set name item _counter namelist
    set points item _counter pointslist
    setxy random-xcor random-ycor
    set shape "person"
    pen-down
    set _counter (_counter + 1)
  ]

  create-games 30 [
    set shape "circle"
    setxy random-xcor random-ycor
    set points random 5 + 1 ;
  ]
  reset-ticks
end 

to go
  ask players[move]
  tick
end

;;this is the part where I added my if-else code but i cannot get it
to move
  ;ask players [  ;ai don't ask player to ask players!
  right(random 181) - 90
  fd 1
  let _hw one-of games-here 
  if _hw != nobody [
    ask _hw [set label "hit"]
    ifelse (points > [points] of _hw) [ ;comparison of two *numbers*
      show "won the game"
    ] [
      show "lost the game"
    ]
  ]
end