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

时间:2015-07-19 04:56:25

标签: if-statement simulation netlogo

所以这就是我正在进行的模拟的进展。此模拟有一个球员列表,每个球员都有他们指定的分数或分数。我有一个叫做游戏的补丁。有三十场比赛。一旦玩家击中游戏(或者如果他们将在模拟中相遇),那么将会有一个标签显示已经完成的“点击”。三十场比赛中的每场比赛都有各自的分数。这些点是随机生成的。

所以我的问题是,如果他们赢了或不赢了比赛,我将如何能够分配球员?我的条件是,如果玩家有一个大于或等于游戏点数的点,那么它应该显示“你赢了比赛!”否则“你输了!”当玩家和游戏相遇时会发生这种情况。

我会在我自己的玩家身上放置另一个变量,表明它是赢还是输。但我的问题是,我一直在尝试编写if-else / if在移动过程中为我想要的条件编码但是我很难过。我需要帮助或一些线索来说明如何做到这一点。谢谢。

$('button').bind('click', alertButtonClick);

1 个答案:

答案 0 :(得分:1)

您的说明并不完全清楚,但我认为这会回答您的问题。 (请查看最后所需的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