HandsOff/Models/Match.cs
/// <summary>
/// Calculates each advance attempt. The only parameters of this method are the amount of 
/// players attacking and defending. The state of the simulation can be deduced from these 
/// amounts and from the current ball owner. For example, with ball owner being 1 and with 1 
/// player attacking and defending, then Team 1 has to be making an attempt to score.
/// </summary>
/// <param name="AmountOfPlayersAttacking"></param>
/// <param name="AmountOfPlayersDefending"></param>
/// <returns></returns>
Calculates each advance attempt. The only parameters of this method are the amount of
players attacking and defending. The state of the simulation can be deduced from these
amounts and from the current ball owner. For example, with ball owner being 1 and with 1
player attacking and defending, then Team 1 has to be making an attempt to score.
Calculates each advance attempt . The only parameters of this method are the amount of players attacking and defending . The state of the simulation can be deduced from these amounts and from the current ball owner . For example with ball owner being 1 and with 1 player attacking and defending then Team 1 has to be making an attempt to score .
private int AttemptAdvance(byte AmountOfPlayersAttacking, byte AmountOfPlayersDefending)
        {
            CombinedAttackTeam1 = 0;
            CombinedDefenseTeam1 = 0;
            CombinedSpeedTeam1 = 0;
            CombinedAttackTeam2 = 0;
            CombinedDefenseTeam2 = 0;
            CombinedSpeedTeam2 = 0;
            TotalTeam1 = 0;
            TotalTeam2 = 0;
            if (BallOwner == 1)
            {
                AttackerAmountCounter = 0; 
                for (AttackerAmountCounter = AmountOfPlayersAttacking; AttackerAmountCounter > 0; AttackerAmountCounter--)
                {
                    SelectedPlayerTeam1 = Team1.Players[RandomPlayerSelector.Next(9, 11)]; 
                    CombinedAttackTeam1 += SelectedPlayerTeam1.Attack;
                    CombinedSpeedTeam1 += SelectedPlayerTeam1.Speed;
                }
                DefenderAmountCounter = 0; 
                for (DefenderAmountCounter = AmountOfPlayersDefending; DefenderAmountCounter > 0; DefenderAmountCounter--)
                {
                    switch (AmountOfPlayersDefending)
                    {
                        case 1:
                            SelectedPlayerTeam2 = Team2.Players[1]; 
                            CombinedDefenseTeam2 += 150;
                            break;
                        case 2:
                        case 3:
                            SelectedPlayerTeam2 = Team2.Players[RandomPlayerSelector.Next(6, 9)]; 
                            break;
                        case 4:
                        default:
                            SelectedPlayerTeam2 = Team2.Players[RandomPlayerSelector.Next(2, 6)]; 
                            break;
                    }
                    CombinedDefenseTeam2 += SelectedPlayerTeam2.Defence;
                    CombinedSpeedTeam2 += SelectedPlayerTeam2.Speed;
                }
                RandomLuck = (RandomChanceGenerator.Next(1, 91));
                TotalTeam1 = (RandomLuck + (CombinedAttackTeam1 / 30) + (CombinedSpeedTeam1 / 30));
                RandomLuck = (RandomChanceGenerator.Next(1, 91));
                TotalTeam2 = (RandomLuck + (CombinedDefenseTeam2 / 30) + (CombinedSpeedTeam2 / 30));
                if ((TotalTeam1 / TotalTeam2) >= 3.4)
                {
                    return 1;
                }
                else if ((TotalTeam1 / TotalTeam2) >= 1.5 && (TotalTeam1 / TotalTeam2) < 3.4)
                {
                    return 0;
                }
                return -1;
            }
            else
            {
                AttackerAmountCounter = 0; 
                for (AttackerAmountCounter = AmountOfPlayersAttacking; AttackerAmountCounter > 0; AttackerAmountCounter--)
                {
                    SelectedPlayerTeam2 = Team2.Players[RandomPlayerSelector.Next(9, 11)]; 
                    CombinedAttackTeam2 += SelectedPlayerTeam2.Attack;
                    CombinedSpeedTeam2 += SelectedPlayerTeam2.Speed;
                }
                DefenderAmountCounter = 0; 
                for (DefenderAmountCounter = AmountOfPlayersDefending; DefenderAmountCounter > 0; DefenderAmountCounter--)
                {
                    switch (AmountOfPlayersDefending)
                    {
                        case 1:
                            SelectedPlayerTeam1 = Team1.Players[1]; 
                            CombinedDefenseTeam2 += 150;
                            break;
                        case 2:
                        case 3:
                            SelectedPlayerTeam1 = Team1.Players[RandomPlayerSelector.Next(6, 9)]; 
                            break;
                        case 4:
                        default:
                            SelectedPlayerTeam1 = Team1.Players[RandomPlayerSelector.Next(2, 6)]; 
                            break;
                    }
                    CombinedDefenseTeam1 += SelectedPlayerTeam1.Defence;
                    CombinedSpeedTeam1 += SelectedPlayerTeam1.Speed;
                }
                RandomLuck = (RandomChanceGenerator.Next(1, 91));
                TotalTeam2 = (RandomLuck + (CombinedAttackTeam2 / 30) + (CombinedSpeedTeam2 / 30));
                RandomLuck = (RandomChanceGenerator.Next(1, 91));
                TotalTeam1 = (RandomLuck + (CombinedDefenseTeam1 / 30) + (CombinedSpeedTeam1 / 30));
                if ((TotalTeam2 / TotalTeam1) >= 3.8)
                {
                    return 1;
                }
                else if ((TotalTeam2 / TotalTeam1) >= 1.0 && (TotalTeam2 / TotalTeam1) < 3.8)
                {
                    return 0;
                }
                return -1;
            }
        }
private int AttemptAdvance ( byte AmountOfPlayersAttacking , byte AmountOfPlayersDefending ) { CombinedAttackTeam1 = 0 ; CombinedDefenseTeam1 = 0 ; CombinedSpeedTeam1 = 0 ; CombinedAttackTeam2 = 0 ; CombinedDefenseTeam2 = 0 ; CombinedSpeedTeam2 = 0 ; TotalTeam1 = 0 ; TotalTeam2 = 0 ; if ( BallOwner == 1 ) { AttackerAmountCounter = 0 ; for ( AttackerAmountCounter = AmountOfPlayersAttacking ; AttackerAmountCounter > 0 ; AttackerAmountCounter -- ) { SelectedPlayerTeam1 = Team1 . Players [ RandomPlayerSelector . Next ( 9 , 11 ) ] ; CombinedAttackTeam1 += SelectedPlayerTeam1 . Attack ; CombinedSpeedTeam1 += SelectedPlayerTeam1 . Speed ; } DefenderAmountCounter = 0 ; for ( DefenderAmountCounter = AmountOfPlayersDefending ; DefenderAmountCounter > 0 ; DefenderAmountCounter -- ) { switch ( AmountOfPlayersDefending ) { case 1 : SelectedPlayerTeam2 = Team2 . Players [ 1 ] ; CombinedDefenseTeam2 += 150 ; break ; case 2 : case 3 : SelectedPlayerTeam2 = Team2 . Players [ RandomPlayerSelector . Next ( 6 , 9 ) ] ; break ; case 4 : default : SelectedPlayerTeam2 = Team2 . Players [ RandomPlayerSelector . Next ( 2 , 6 ) ] ; break ; } CombinedDefenseTeam2 += SelectedPlayerTeam2 . Defence ; CombinedSpeedTeam2 += SelectedPlayerTeam2 . Speed ; } RandomLuck = ( RandomChanceGenerator . Next ( 1 , 91 ) ) ; TotalTeam1 = ( RandomLuck + ( CombinedAttackTeam1 / 30 ) + ( CombinedSpeedTeam1 / 30 ) ) ; RandomLuck = ( RandomChanceGenerator . Next ( 1 , 91 ) ) ; TotalTeam2 = ( RandomLuck + ( CombinedDefenseTeam2 / 30 ) + ( CombinedSpeedTeam2 / 30 ) ) ; if ( ( TotalTeam1 / TotalTeam2 ) >= 3.4 ) { return 1 ; } else if ( ( TotalTeam1 / TotalTeam2 ) >= 1.5 && ( TotalTeam1 / TotalTeam2 ) < 3.4 ) { return 0 ; } return - 1 ; } else { AttackerAmountCounter = 0 ; for ( AttackerAmountCounter = AmountOfPlayersAttacking ; AttackerAmountCounter > 0 ; AttackerAmountCounter -- ) { SelectedPlayerTeam2 = Team2 . Players [ RandomPlayerSelector . Next ( 9 , 11 ) ] ; CombinedAttackTeam2 += SelectedPlayerTeam2 . Attack ; CombinedSpeedTeam2 += SelectedPlayerTeam2 . Speed ; } DefenderAmountCounter = 0 ; for ( DefenderAmountCounter = AmountOfPlayersDefending ; DefenderAmountCounter > 0 ; DefenderAmountCounter -- ) { switch ( AmountOfPlayersDefending ) { case 1 : SelectedPlayerTeam1 = Team1 . Players [ 1 ] ; CombinedDefenseTeam2 += 150 ; break ; case 2 : case 3 : SelectedPlayerTeam1 = Team1 . Players [ RandomPlayerSelector . Next ( 6 , 9 ) ] ; break ; case 4 : default : SelectedPlayerTeam1 = Team1 . Players [ RandomPlayerSelector . Next ( 2 , 6 ) ] ; break ; } CombinedDefenseTeam1 += SelectedPlayerTeam1 . Defence ; CombinedSpeedTeam1 += SelectedPlayerTeam1 . Speed ; } RandomLuck = ( RandomChanceGenerator . Next ( 1 , 91 ) ) ; TotalTeam2 = ( RandomLuck + ( CombinedAttackTeam2 / 30 ) + ( CombinedSpeedTeam2 / 30 ) ) ; RandomLuck = ( RandomChanceGenerator . Next ( 1 , 91 ) ) ; TotalTeam1 = ( RandomLuck + ( CombinedDefenseTeam1 / 30 ) + ( CombinedSpeedTeam1 / 30 ) ) ; if ( ( TotalTeam2 / TotalTeam1 ) >= 3.8 ) { return 1 ; } else if ( ( TotalTeam2 / TotalTeam1 ) >= 1.0 && ( TotalTeam2 / TotalTeam1 ) < 3.8 ) { return 0 ; } return - 1 ; } }
Calculates each advance attempt.
Calculates each advance attempt .
// reset all values // get numbers for the attacking team (team 1) // reset this value every time a calculation is made // randomly choose between attackers // get numbers for the defending team (team 2) // reset this value every time a calculation is made // only one defender, therefore the keeper is chosen // randomly choose between mid-fielders // randomly choose between defenders /** calculate if attacking team will be successful **/ // get numbers for the attacking team (team 2) // reset this value every time a calculation is made // randomly choose between attackers // get numbers for the defending team (team 1) // reset this value every time a calculation is made // only one defender, therefore the keeper is chosen // randomly choose between mid-fielders // randomly choose between defenders /** calculate if attacking team will be successful */
None
AmountOfPlayersAttacking
byte
None
AmountOfPlayersDefending
byte
None