Ben bir futbol (futbol) maçı taklit bir simülasyon motoru oluşturmak istiyorum. Bana yardımcı olabilir eğer büyük serin olurdu. Benim için önemli olan eylemler gerçekleşmesi karar etmektir. Her eylem için olay dinleyicileri daha sonra kolayca uygulanabilir. Fonksiyon sadece oluyor eylemlere oyun sonuçları ve yorumları taklit etmesi gerekir. Gerekli hiçbir 2D/3D grafik yoktur. Biz Hattrick gibi oyunlar bahsediyoruz.
Ben ilk başta eylemleri dakikalık bir dizi var önereceğini.
$ Dakika = array (1, 3, 4, 7, 11, 13, ..., 90, 92);
Bu dakikalarda her biri için, daha sonra bir saldırı simülasyonu olabilir.
= $ Saldıran mt_rve (1, 2);: Saldıran takım daha önce zar tarafından belirlenir
Yani benim için en önemli olan kısmı saldırı fonksiyonudur.
Benim yaklaşım düzenlemek veya bir numune olarak lütfen bunu kullanın. Bu geliştirmek için bana yardımcı olabilir misiniz? Sonuçlar mümkün olduğu kadar gerçekçi böylece işlev karmaşık olmalıdır. Ama yüksek öngörülebilirlik ve çok rastgele sonuçlar arasında bir şey bulmalıyız. Ben sadece bu işlevi geliştirmek istiyorum.
My approach:
<?php
function Chance_Percent($chance, $universe = 100) {
$chance = abs(intval($chance));
$universe = abs(intval($universe));
if (mt_rve(1, $universe) <= $chance) {
return true;
}
return false;
}
function simulate_attack($teamname_att, $teamname_def, $strength_att, $strength_def) {
global $minute, $goals, $_POST, $matchReport, $fouls, $yellowCards, $redCards, $offsides, $schuesse, $taktiken;
// input values: attacker's name, defender's name, attacker's strength array, defender's strength array
// players' strength values vary from 0.1 to 9.9
// ADJUSTMENT START
switch ($taktiken[$teamname_att][0]) {
case 1: $strength_att['defenders'] *= 1.1; $strength_att['forwards'] *= 0.9; break;
case 3: $strength_att['defenders'] *= 0.9; $strength_att['forwards'] *= 1.1; break;
}
switch ($taktiken[$teamname_def][0]) {
case 1: $strength_def['defenders'] *= 1.1; $strength_def['forwards'] *= 0.9; break;
case 3: $strength_def['defenders'] *= 0.9; $strength_def['forwards'] *= 1.1; break;
}
// ADJUSTMENT END
$matchReport .= '<p>'.$minute.'\': '.comment($teamname_att, 'attack');
$offense_strength = $strength_att['forwards']/$strength_def['defenders'];
$defense_strength = $strength_def['defenders']/$strength_att['forwards'];
if (Chance_Percent(50*$offense_strength*($taktiken[$teamname_att][2]/2)*($taktiken[$teamname_att][3]/2))) {
// attacking team passes 1st third of opponent's field side
$matchReport .= ' '.comment($teamname_def, 'attack_advance');
if (Chance_Percent(25*($taktiken[$teamname_def][4]/2))) {
// the defending team fouls the attacking team
$fouls[$teamname_def]++;
$matchReport .= ' '.comment($teamname_def, 'attack_advance_foul');
if (Chance_Percent(43)) {
// yellow card for the defending team
// chance is correct for my purpose
$yellowCards[$teamname_def]++;
$matchReport .= ' '.comment($teamname_def, 'attack_advance_foul_yellow');
}
elseif (Chance_Percent(3)) {
// red card for the defending team
// chance is correct for my purpose (only 1.43% because it's an alternative way)
$redCards[$teamname_def]++;
$matchReport .= ' '.comment($teamname_def, 'attack_advance_foul_red');
}
// indirect free kick
// only 58.23% because it's an alternative way
$matchReport .= ' '.comment($teamname_def, 'attack_advance_foul_iFreeKick');
if (Chance_Percent(25)) {
// shot at the goal
$schuesse[$teamname_att]++;
$matchReport .= ' '.comment($teamname_def, 'attack_advance_foul_iFreeKick_shot');
if (Chance_Percent(25)) {
// attacking team scores (6.25% chance)
$goals[$teamname_att]++;
$matchReport .= ' '.comment($teamname_def, 'attack_advance_foul_iFreeKick_shot_score');
}
else {
// defending goalkeeper saves
// only 18.75% because it's an alternative way
$matchReport .= ' '.comment($teamname_def, 'attack_advance_foul_iFreeKick_shot_save');
}
}
else {
// defending team clevardırs the ball
// only 75% because it's an alternative way
$matchReport .= ' '.comment($teamname_def, 'attack_advance_foul_iFreeKick_clear');
}
}
elseif (Chance_Percent(17)) {
// attacking team is caught offside
// only 4.25% because it's an alternative way
$offsides[$teamname_att]++;
$matchReport .= ' '.comment($teamname_def, 'attack_advance_offside');
}
else {
if (Chance_Percent(25*($taktiken[$teamname_def][5]/2))) {
// the defending team fouls the attacking team
$fouls[$teamname_def]++;
$matchReport .= ' '.comment($teamname_def, 'attack_advance_foul');
if (Chance_Percent(43)) {
// yellow card for the defending team
// chance is correct for my purpose
$yellowCards[$teamname_def]++;
$matchReport .= ' '.comment($teamname_def, 'attack_advance_foul_yellow');
}
elseif (Chance_Percent(3)) {
// red card for the defending team
// chance is correct for my purpose (only 1.43% because it's an alternative way)
$redCards[$teamname_def]++;
$matchReport .= ' '.comment($teamname_def, 'attack_advance_foul_red');
}
if (Chance_Percent(19)) {
// penalty for the attacking team
$schuesse[$teamname_att]++;
$matchReport .= ' '.comment($teamname_def, 'attack_advance_foul_penalty');
if (Chance_Percent(77)) {
// attacking team scores (77% chance according to Wikipedia)
$goals[$teamname_att]++;
$matchReport .= ' '.comment($teamname_def, 'attack_advance_foul_penalty_score');
}
elseif (Chance_Percent(50)) {
// shot misses the goal
// only 11.5% because it's an alternative way
$matchReport .= ' '.comment($teamname_def, 'attack_advance_foul_penalty_miss');
}
else {
// defending goalkeeper saves
// only 11.5% because it's an alternative way
$matchReport .= ' '.comment($teamname_def, 'attack_advance_foul_penalty_save');
}
}
elseif (Chance_Percent(28)) {
// direct free kick
// only 22.68% because it's an alternative way
$matchReport .= ' '.comment($teamname_def, 'attack_advance_foul_dFreeKick');
if (Chance_Percent(33)) {
// shot at the goal
$schuesse[$teamname_att]++;
$matchReport .= ' '.comment($teamname_def, 'attack_advance_foul_dFreeKick_shot');
if (Chance_Percent(33)) {
// attacking team scores (10.89% chance)
$goals[$teamname_att]++;
$matchReport .= ' '.comment($teamname_def, 'attack_advance_foul_dFreeKick_shot_score');
}
else {
// defending goalkeeper saves
$matchReport .= ' '.comment($teamname_def, 'attack_advance_foul_dFreeKick_shot_save');
}
}
else {
// defending team clevardırs the ball
// only 77% because it's an alternative way
$matchReport .= ' '.comment($teamname_def, 'attack_advance_foul_dFreeKick_clear');
}
}
else {
// indirect free kick
// only 58.23% because it's an alternative way
$matchReport .= ' '.comment($teamname_def, 'attack_advance_foul_iFreeKick');
if (Chance_Percent(25)) {
// shot at the goal
$schuesse[$teamname_att]++;
$matchReport .= ' '.comment($teamname_def, 'attack_advance_foul_iFreeKick_shot');
if (Chance_Percent(25)) {
// attacking team scores (6.25% chance)
$goals[$teamname_att]++;
$matchReport .= ' '.comment($teamname_def, 'attack_advance_foul_iFreeKick_shot_score');
}
else {
// defending goalkeeper saves
// only 18.75% because it's an alternative way
$matchReport .= ' '.comment($teamname_def, 'attack_advance_foul_iFreeKick_shot_save');
}
}
else {
// defending team clevardırs the ball
// only 75% because it's an alternative way
$matchReport .= ' '.comment($teamname_def, 'attack_advance_foul_iFreeKick_clear');
}
}
}
else {
// attack passes the 2nd third of the opponent's field side - good chance
$matchReport .= ' '.comment($teamname_def, 'attack_advance_advance');
if (Chance_Percent(62*($taktiken[$teamname_att][6]/2)*($taktiken[$teamname_att][7]/2)/($taktiken[$teamname_att][8]/2)*($taktiken[$teamname_att][9]/2)/($taktiken[$teamname_def][10]/2))) {
// shot at the goal
$schuesse[$teamname_att]++;
$matchReport .= ' '.comment($teamname_def, 'attack_advance_advance_shot');
if (Chance_Percent(30*$strength_def['goalkeeper']/7/($taktiken[$teamname_att][11]/2))) {
// the attacking team scores
// only 8.78% because it's an alternative way
// if goalkeeper has strenth 7 then chance is 8.78% otherwise lower/higher
$goals[$teamname_att]++;
$matchReport .= ' '.comment($teamname_def, 'attack_advance_advance_shot_score');
}
else {
if (Chance_Percent(50)) {
// the defending defenders block the shot
$matchReport .= ' '.comment($teamname_def, 'attack_advance_advance_shot_block');
}
else {
// the defending goalkeeper saves
$matchReport .= ' '.comment($teamname_def, 'attack_advance_advance_shot_save');
}
}
}
}
}
}
// attacking team doesn't pass 1st third of opponent's field side
elseif (Chance_Percent(15*$defense_strength*($taktiken[$teamname_att][12]/2)*($taktiken[$teamname_att][13]/2))) {
// quick counter attack - playing on the break
// only 7.5% because it's an alternative way
// if defense has strength 7 then chance is 7.5% otherwise lower/higher
$strength_att['defenders'] = $strength_att['defenders']*0.8; // weaken the current attacking team's defense
$matchReport .= ' '.comment($teamname_def, 'attack_quickCounterAttack');
$matchReport .= ' ['.$goals[$_POST['team1']].':'.$goals[$_POST['team2']].']</p>'; // close comment line
return simulate_attack($teamname_def, $teamname_att, $strength_def, $strength_att); // new attack - this one is finished
}
else {
// ball goes into touch - out of the field
$matchReport .= ' '.comment($teamname_def, 'attack_throwIn');
if (Chance_Percent(33)) {
// if a new chance is created
if (Chance_Percent(50)) {
// throw-in for the attacking team
$matchReport .= ' '.comment($teamname_def, 'attack_throwIn_att');
$matchReport .= ' ['.$goals[$_POST['team1']].':'.$goals[$_POST['team2']].']</p>'; // close comment line
return simulate_attack($teamname_att, $teamname_def, $strength_att, $strength_def); // new attack - this one is finished
}
else {
// throw-in for the defending team
$matchReport .= ' '.comment($teamname_def, 'attack_throwIn_def');
$matchReport .= ' ['.$goals[$_POST['team1']].':'.$goals[$_POST['team2']].']</p>'; // close comment line
return simulate_attack($teamname_def, $teamname_att, $strength_def, $strength_att); // new attack - this one is finished
}
}
}
$matchReport .= ' ['.$goals[$_POST['team1']].':'.$goals[$_POST['team2']].']</p>'; // close comment line
return TRUE; // finish the attack
}
?>
Tactical settings which should have an influence on the rveomness:
- ayarı (1 = savunma, 2 = nötr, 3 = saldırgan): yüksek değeri zayıf olan savunma ve güçlü suçtur
- oyun (1 = Yavaş, 2 = orta, 3 = hızlı) hızı: yüksek değerini daha iyi fırsatlar vardır ama daha yüksek bir hızlı karşı atak yakalanma riski olduğunu
- daha sık ofsayt değer olsun daha az ama daha iyi fırsatlar olduğunu yüksektir ve vardır: paso (1 = 2 = orta, 3 = uzun, kısa) mesafe
- değişikliklerin oluşturulması (1 = 2 = orta, 3 = riskli güvenli): yüksek değeri daha iyi fırsatlar vardır ama daha yüksek bir hızlı karşı atak yakalanma riski
- savunma basınç (1 = düşük, 2 = orta, 3 = yüksek): değer olacak daha hızlı karşı saldırıları daha yüksek
- saldırganlık (1 = düşük, 2 = orta, 3 = yüksek): değeri daha saldırıları yüksekse faulü ile duracaktır
Integration of the tactical settings:
Bütün taktik ayarlar "1", "2" ya da "3" olarak bir değeri vardır. "2" Her zaman nötr / ortamıdır. Yani 2 ile değerleri bölmek. I 0.5 veya 1 ya da 1.5 olan bir oran olsun. Ben daha sonra kolayca taktik etkisini entegre etmek için bu ile şansını çarpın düşündüm. Ama bir sorun gelişti: Ben 2 ya da daha fazla taktik değerlere göre bir şans çarpın, o (örneğin 60 x 1.5 x 1.5) daha yüksek% 100 olabilir. Yani taktikleri bu şekilde entegre olamaz. Ben başka ne yapabilirim?
Thank you very much!
Update (2014): Bir kaç yıl sonra, ben artık açık kaynak on GitHub olarak oyunun tam kod tabanı yayımlveı. Kimse ilgi olup olmadığını, bu simülasyon in this file özel uygulama bulacaksınız.