足球投注的可能性

时间:2016-10-14 12:11:36

标签: javascript

我想展示游戏可能结束的一切可能方式。

我有一个表单,用户可以在其中添加每个足球比赛。

现在我想在表格中显示比赛可能结束的所有可能方式。

e.g:

  • team1 vs. team2,
  • team3 vs team4

表(赢/输/抽奖)应该是这样的:

  • team1,team3
  • team1,team4
  • team1,team3 team4 draw
  • team2,team3
  • team2,team4
  • team2,team3 team4 draw
  • team3,team1 team2 draw
  • team4,team1 team2 draw
  • team1 team2 draw,team3 team4 draw

1 个答案:

答案 0 :(得分:0)

以下示例尝试每个独特的团队组合,并列出每个可能结果的结果。

https://en.wikipedia.org/wiki/Combinatorics



var teams = [1, 2, 3, 4];
var fallouts = ["win", "lose", "draw"];
for (var ti1 = 0; ti1 < teams.length; ti1++) {
  var t1 = teams[ti1];
  for (var ti2 = ti1 + 1; ti2 < teams.length; ti2++) {
    if (ti1 == ti2) {
      continue;
    }
    var t2 = teams[ti2];
    for (var f = 0; f < fallouts.length; f++) {
      var fallout = fallouts[f];
      document.write("Team " + t1 + " matches against team " + t2 + " for a " + fallout + "<br/>")
    }
  }
}
&#13;
&#13;
&#13;