• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

[Solved] Help me to compare integers for a final game result

Status
Not open for further replies.
Can anyone help me for the programming logic to find the winning team in a game?
if all are equal then the game is a draw
if one team has teh highest score he is the winner
if two or three teams hold the highest score simultaneously , they split the win....
there are 4 teams
int Team_Score[]

outcome:
team (index) is the winner / teams index,index are the winners / Draw!


it may be done with triggers or JASS.
 
Level 25
Joined
Sep 26, 2009
Messages
2,381
Something like this should work
  • Get Winners
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • -------- Test data --------
      • Set VariableSet Team_Score[1] = 50
      • Set VariableSet Team_Score[2] = 10
      • Set VariableSet Team_Score[3] = 50
      • Set VariableSet Team_Score[4] = 50
      • -------- Logic to determine winner --------
      • Set VariableSet Highest_Score = -1
      • Set VariableSet Number_Of_Teams = 4
      • Set VariableSet Message = <Empty String>
      • For each (Integer loopIndex) from 1 to Number_Of_Teams, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Team_Score[loopIndex] Greater than Highest_Score
            • Then - Actions
              • Set VariableSet Highest_Score = Team_Score[loopIndex]
              • Set VariableSet Winners_Count = 1
              • Set VariableSet Winners[Winners_Count] = loopIndex
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Team_Score[loopIndex] Equal to Highest_Score
                • Then - Actions
                  • Set VariableSet Winners_Count = (Winners_Count + 1)
                  • Set VariableSet Winners[Winners_Count] = loopIndex
                • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Winners_Count Equal to Number_Of_Teams
        • Then - Actions
          • Set VariableSet Message = Draw!
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Winners_Count Equal to 1
            • Then - Actions
              • Set VariableSet Message = (Team + ((String(Winners[Winners_Count])) + is the winner!))
            • Else - Actions
              • Set VariableSet Message = Teams
              • For each (Integer loopIndex) from 1 to Winners_Count, do (Actions)
                • Loop - Actions
                  • Set VariableSet Message = (Message + (String(Winners[loopIndex])))
                  • -------- The below If/Then/Else just checks if it should add the separator ', ' between team numbers --------
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • loopIndex Less than Winners_Count
                    • Then - Actions
                      • Set VariableSet Message = (Message + , )
                    • Else - Actions
              • Set VariableSet Message = (Message + are the winners!)
      • Game - Display to (All players) the text: Message
 
Something like this should work
  • Get Winners
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • -------- Test data --------
      • Set VariableSet Team_Score[1] = 50
      • Set VariableSet Team_Score[2] = 10
      • Set VariableSet Team_Score[3] = 50
      • Set VariableSet Team_Score[4] = 50
      • -------- Logic to determine winner --------
      • Set VariableSet Highest_Score = -1
      • Set VariableSet Number_Of_Teams = 4
      • Set VariableSet Message = <Empty String>
      • For each (Integer loopIndex) from 1 to Number_Of_Teams, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Team_Score[loopIndex] Greater than Highest_Score
            • Then - Actions
              • Set VariableSet Highest_Score = Team_Score[loopIndex]
              • Set VariableSet Winners_Count = 1
              • Set VariableSet Winners[Winners_Count] = loopIndex
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Team_Score[loopIndex] Equal to Highest_Score
                • Then - Actions
                  • Set VariableSet Winners_Count = (Winners_Count + 1)
                  • Set VariableSet Winners[Winners_Count] = loopIndex
                • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Winners_Count Equal to Number_Of_Teams
        • Then - Actions
          • Set VariableSet Message = Draw!
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Winners_Count Equal to 1
            • Then - Actions
              • Set VariableSet Message = (Team + ((String(Winners[Winners_Count])) + is the winner!))
            • Else - Actions
              • Set VariableSet Message = Teams
              • For each (Integer loopIndex) from 1 to Winners_Count, do (Actions)
                • Loop - Actions
                  • Set VariableSet Message = (Message + (String(Winners[loopIndex])))
                  • -------- The below If/Then/Else just checks if it should add the separator ', ' between team numbers --------
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • loopIndex Less than Winners_Count
                    • Then - Actions
                      • Set VariableSet Message = (Message + , )
                    • Else - Actions
              • Set VariableSet Message = (Message + are the winners!)
      • Game - Display to (All players) the text: Message
The expert has arrived. Thanks!
 
Status
Not open for further replies.
Top