Bonjour,

j'ai un problème avec un script que j'ai commençé à faire.
Attention il faut avoir quelques connaissances en POO pour comprendre le script.

Quand je le lance, des fois ça marche, des fois ça fait planter apache et je dois carrément désinstaller le service pour arrêter le bug.
(Ca fait une genre boucle infinie je vois pas d'où ça vient)

C'est un script qui reproduit un match de foot en comptes-rendus.

Merci de m'aider ! (Même avec Zend j'arrive pas à le débugger, et j'ai réinstallé la dernière version d'apache & PHP)

Source :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
 
<?php
 echo "<pre>";
 ////////////////////////////////////////////////////////////////////////
  class team{
 
    public $defenses=array(); // Tous les joueurs défenseurs
    public $millieux=array(); // Tous les joueurs du millieu
    public $attaques=array(); // Tous les attaquants
    public $goal;
        function add_def($name){                 // Ajoute un défenseur
                 array_push($this->defenses, $name);
        }
        function add_mid($name){
                 array_push($this->millieux, $name);
        }
        function add_att($name){
                 array_push($this->attaques, $name);
        }
        function add_goal($name){
         $this->goal=$name;
        }
  }
//////////////////////////////////////////////////////////////////////////
  class hasard{
 
   public $total=0;
   public $funcs=array();
   public $nbr=0;
 
        function add($func, $pcent) {
             $this->total+=$pcent;
             array_push($this->funcs, array($func, $this->total+1));
             $this->nbr++;
             if($this->total>100) die("FATAL ERROR, ref: has01");
        }
        function choose($x) {
          if($this->total!=100) die("FATAL ERROR, ref: has02 $this / ".$this->total);
         $rand=rand(1,100);
           foreach($this->funcs as $value) {
               if($rand<$value[1]) {
                 $fonc=$value[0];
                 $x->$fonc();
                return($fonc);
               }
           }
        }
  }
/////////////////////////////////////////////////////////////////////////
 
             $act00    =      new hasard;
             $act11    =      new hasard;
             $act12    =      new hasard;
             $act22    =      new hasard;
             $act21    =      new hasard;
             $act30    =      new hasard;
 
              $act00->add("tir", 2);
              $act00->add("tir_contre_1", 1);
              $act00->add("tir_contre_23", 1);
              $act00->add("passe_zone", 8);
              $act00->add("passe_zone_contre", 5);
              $act00->add("passe_avant", 20);
              $act00->add("passe_avant_contre", 10);
              $act00->add("passe_arriere", 15);
              $act00->add("passe_arriere_contre", 5);  
              $act00->add("tacle", 10);
              $act00->add("sortie", 10);
              $act00->add("drible", 13);
 
              $act11->add("passe_zone", 10);
              $act11->add("passe_longue", 10);
              $act11->add("passe_longue_contre", 10);
              $act11->add("passe_avant", 25);
              $act11->add("passe_avant_contre", 10);
              $act11->add("passe_arriere", 10);
              $act11->add("tacle", 5);
              $act11->add("sortie", 10);
              $act11->add("drible", 10);
 
              $act21->add("passe_zone", 10);
              $act21->add("passe_zone_contre", 5);
              $act21->add("passe_longue", 15);
              $act21->add("passe_longue_contre", 7);
              $act21->add("passe_Tlongue", 10);
              $act21->add("passe_Tlongue_contre", 5);
              $act21->add("passe_avant", 20);
              $act21->add("passe_avant_contre", 8);
              $act21->add("sortie", 5);
              $act21->add("drible", 10);
 
              $act12->add("passe_zone", 10);
              $act12->add("passe_zone_contre", 4);
              $act12->add("passe_avant", 18);
              $act12->add("passe_avant_contre", 5);
              $act12->add("passe_arriere", 10);
              $act12->add("passe_arriere_contre", 5);
              $act12->add("tacle", 10);
              $act12->add("sortie", 10);
              $act12->add("drible", 10);
              $act12->add("corner", 5);
              $act12->add("tir", 8);
              $act12->add("tir_contre_1", 5);
 
              $act22->add("passe_zone", 8);
              $act22->add("passe_zone_contre", 6);
              $act22->add("passe_arriere", 10);
              $act22->add("passe_arriere_contre", 8);
              $act22->add("tacle", 10);
              $act22->add("sortie", 8);
              $act22->add("corner", 8);
              $act22->add("tir", 12);
              $act22->add("tir_contre_23", 8);
              $act22->add("penalty", 2);
              $act22->add("coup_franc", 8);
              $act22->add("hors_jeu", 12);
 
 
////////////////////////////////////////////////////////////////
  class partie{
       public $team1;  // la classe de l'équipe 1
       public $team2;
      public $pos_ball=0; // Position de la balle
       public $side_ball=0; // Camp de la balle
       public $own_ball; // Possesseur de la balle
       public $own_team_ball=0;
       public $time; // Temps dans le match en minutes, secondes
       public $time_sup;
       public $buts=array(0,0); // Array (1 => Team1; 2=> Team2);  
       public $cr=array();
 
           function cr($add){
             $add=$add." ".$this->pos_ball;
            array_push($this->cr, $add);
           }
           function first_own() {
            $nteam=rand(1,2);
            $player=$this->find_player($nteam, 0);
            $this->own_ball=$player;
            $this->own_team_ball=$nteam;
            $this->cr("Le jeu est lançé ! Le joueur $player prend la balle");
           }
           function partie($t1, $t2){
            $this->team1=$t1;
            $this->team2=$t2;
           $this->first_own();
           }
           function cball($x, $side) { // change la position de la balle
            $this->pos_ball=$x;
            $this->side_ball=$side;
           }
           function find_player($t, $pos, $except=0) {
           if($pos==0) $pos="millieux"; elseif($pos==1) $pos="defenses"; elseif($pos==2) $pos="attaques"; elseif($pos==3) $pos="goal";
             do {
               $arr=$this->{"team".$t}->{$pos}[0];
           @$v=array_rand($arr) ;
           $p=$this->{"team".$t}->{$pos}[0][$v];
             }while($p!=$except);
           return $this->{"team".$t}->{$pos}[0][$v];
           }
           function passe_avant(){
             $opp=3-$this->own_team_ball;
               $ob=$this->own_ball;
 
                    if($this->side_ball==0)
                    {
                     $this->pos_ball++;
                     $this->own_ball=$this->find_player($this->own_team_ball, 0, $this->own_ball);
                     $this->side_ball=$opp;
 
 
                    }
                    elseif($this->own_team_ball==$this->side_ball)
                    {
 
                     $this->pos_ball--;
                    if($this->pos_ball==1) $this->side_ball=0;
                     $this->own_ball=$this->find_player($this->own_team_ball, $this->pos_ball, $this->own_ball);
                    }
                    else
                    {
                    $this->pos_ball++;
                   $this->own_ball=$this->find_player($this->own_team_ball, 2, $this->own_ball);
                    }
                     $this->cr("$ob fait une passe avant à ".$this->own_ball);
           }
           function passe_longue() {
                       $opp=3-$this->own_team_ball;
                 if($this->pos_ball==1)
                  $this->side_ball=$opp;
                 else {
                 $this->side_ball=0;
                  $this->pos_ball=0;
                 }
                 $this->own_ball=$this->find_player($this->own_team_ball, 0, $this->own_ball);
           }
           function passe_longue_contre() {
           $opp=3-$this->own_team_ball;
                 if($this->pos_ball==1)
                  $this->side_ball=$opp;
                 else {
                 $this->side_ball=0;
                  $this->pos_ball=0;
                 }
                 $this->own_ball=$this->find_player($opp, 0);
           }
           function passe_Tlongue() {
              $opp=3-$this->own_team_ball;
            $this->side_ball=$opp;
            $this->pos_ball=1;
            $this->own_ball=$this->find_player($this->own_team_ball, 0, $this->own_ball);
           }
           function passe_Tlongue_contre() {
              $opp=3-$this->own_team_ball;
            $this->side_ball=$opp;
            $this->pos_ball=1;
            $this->own_ball=$this->find_player($opp, 0);
           }
           function passe_avant_contre(){
                  $opp=3-$this->own_team_ball;
                  $this->own_team_ball=$opp;
                    $ob=$this->own_ball;
 
                    if($this->side_ball==0)
                    {
                     $this->pos_ball++;
                     $this->own_ball=$this->find_player($opp, 1);
                     $this->side_ball=$opp;
 
                    }
                    elseif($this->own_team_ball==$this->side_ball)
                    {
                     $this->pos_ball--;
                    if($this->pos_ball==1) $this->side_ball=0;
                     $this->own_ball=$this->find_player($opp, 0);
 
                    }
                    else
                    {
                     $this->pos_ball++;
                   $this->own_ball=$this->find_player($opp, 1);
 
                    }
                              $this->cr("$ob tente une passe en avant mais se fait contrer par ".$this->own_ball." qui prend la balle");
           }
           function passe_arriere(){
                $opp=3-$this->own_team_ball;
                $ob=$this->own_ball;
 
            if($this->side_ball==0)
                    {
                     $this->pos_ball++;
                     $this->own_ball=$this->find_player($this->own_team_ball, 1);
                     $this->side_ball=$this->own_team_ball;
                    }
                    elseif($this->own_team_ball==$this->side_ball)
                    {
                     $this->own_ball=$this->find_player($this->own_team_ball, 1, $this->own_ball);
                    }
                    else
                    {
                     if($this->side_ball==1) $this->side_ball=0;
                     $this->pos_ball--;
                     $this->own_ball=$this->find_player($this->own_team_ball, 0, $this->own_ball);
                    }
                      $this->cr("$ob fait une passe en arrière à ".$this->own_ball);
           }
           function passe_arriere_contre(){
                $opp=3-$this->own_team_ball;
                  $this->own_team_ball=$opp;
                      $ob=$this->own_ball;
 
            if($this->side_ball==0)
                    {
                     $this->pos_ball++;
                     $this->own_ball=$this->find_player($opp, 0);
                     $this->side_ball=$this->own_team_ball;
                    }
                    elseif($this->own_team_ball==$this->side_ball)
                    {
                     $this->own_ball=$this->find_player($opp, 2, $this->own_ball);
                    }
                    else
                    {
                     if($this->side_ball==1) $this->side_ball=0;
                     $this->pos_ball--;
                     $this->own_ball=$this->find_player($opp, 0);
                    }
                             $this->cr("$ob tente une passe en arrière mais se fait contrer par ".$this->own_ball." qui prend la balle");
           }
           function drible(){
             $opp=3-$this->own_team_ball;
             $this->own_team_ball=$opp;
                                 $ob=$this->own_ball;
 
              if($this->own_team_ball==$this->side_ball)
              {
                  if($this->pos_ball==1)    $this->own_ball=$this->find_player($opp, 0);
                  else   $this->own_ball=$this->find_player($opp, 2);
              }
              else  $this->own_ball=$this->find_player($opp, 1);
                      $this->cr("$ob tente de dribler ".$this->own_ball." mais perd la balle");
           }
           function tir(){
             $ob=$this->own_ball;
           $opp=3-$this->own_team_ball;
           $this->buts[$this->own_team_ball]++;
           $this->pos_ball=0;
           $this->side_ball=0;
           $this->own_team_ball=$opp;
           $this->own_ball=$this->find_player($opp, 0);
           $this->cr("$ob tire et marque un but ! GOOOOOAAAAAAAL !!!! La balle est remise en jeu, ".$this->own_ball." reprend la balle au millieu.");
           }
           function tir_contre_23(){
           $opp=3-$this->own_team_ball;
             $this->own_team_ball=$opp;
           $luck=rand(1,2);
                           if($luck==1) 
                           {
                             $this->pos_ball=3;
                             $this->own_ball=$this->find_player($opp,3);
                           }
                           else
                           {
                             $this->pos_ball=3;
                             $this->own_ball=$this->find_player($opp, 1);
                           }
 
           }
           function tir_contre_1(){
                    $opp=3-$this->own_team_ball;
                    $this->own_team_ball=$opp;
                    $this->pos_ball=1;
                    $this->own_ball=$this->find_player($opp,1);
           }
           function sortie(){
             $ob=$this->own_ball;
             $opp=3-$this->own_team_ball;
             $this->own_team_ball=$opp;
              if($this->own_team_ball==$this->side_ball)
              {
                  if($this->pos_ball==1)    $this->own_ball=$this->find_player($opp, 0);
                  else   $this->own_ball=$this->find_player($opp, 2);
              }
              else  $this->own_ball=$this->find_player($opp, 1);
                 $this->cr("$ob fait une sortie. La balle est renvoyée à ".$this->own_ball);
 
 
           }
           function corner(){
             $nteam=rand(1,2);
             if($this->side_ball==$nteam)
            $player=$this->find_player($nteam, 1);
            else 
            $player=$this->find_player($nteam, 2);
 
            $this->own_ball=$player;
            $this->own_team_ball=$nteam;
           }
           function tacle() {
             $ob=$this->own_ball;
             $opp=3-$this->own_team_ball;
             $this->own_team_ball=$opp;
              if($this->own_team_ball==$this->side_ball)
              {
                  if($this->pos_ball==1)    $this->own_ball=$this->find_player($opp, 0);
                  else   $this->own_ball=$this->find_player($opp, 2);
              }
              else  $this->own_ball=$this->find_player($opp, 1);
                 $this->cr($this->own_ball." a taclé $ob et lui a pris la balle");
 
           }
           function passe_zone(){
             $ob=$this->own_ball;
             $opp=3-$this->own_team_ball;
              if($this->own_team_ball==$this->side_ball)
              $this->own_ball=$this->find_player($this->own_ball, 1, $this->own_ball);
              else  { if($this->pos_ball<=1) $this->own_ball=$this->find_player($opp, 0); 
              else $this->own_ball=$this->find_player($opp, 2);}
                 $this->cr("$ob fait une passe à ".$this->own_ball);
           }
           function passe_zone_contre(){
             $ob=$this->own_ball;
                $opp=3-$this->own_team_ball;
             $this->own_team_ball=$opp;
              if($this->own_team_ball==$this->side_ball)
              {
                  if($this->pos_ball==1)    $this->own_ball=$this->find_player($opp, 0);
                  else   $this->own_ball=$this->find_player($opp, 2);
              }
              else  $this->own_ball=$this->find_player($opp, 1);
                $this->cr("$ob tente une passe mais se fait contrer par ".$this->own_ball." qui prend la balle");
           }
           function hors_jeu(){
              $opp=3-$this->own_team_ball;
              $this->own_team_ball=$opp;
              $this->own_ball=$this->find_player($opp, 1);
           }
           function coup_franc(){
 
           }
           function penalty(){
 
           }       
           function action($z=1) {
              global $act00, $act11, $act12, $act21, $act22, $act30;
              for($y=0; $y<=$z; $y++) {
             if($this->pos_ball==0 || $this->pos_ball==3) $plus=0;
             elseif($this->own_team_ball==$this->side_ball) $plus=1;
             else $plus=2;
             $var="act".$this->pos_ball.$plus;
              $$var->choose($this);
 
              }
           }
}
////////////////////////////////////////////////////////////////////////
  $home=new team;
  $home->add_goal("Tiz");
  $home->add_def(array("Bear", "Robot", "Blok", "Cage"));
  $home->add_mid(array("Rabbit", "Dog", "Cat", "Duck"));
  $home->add_att(array("Wolf", "Panther"));
  $away=new team;
  $away->add_goal("Arkk");
   $away->add_def(array("Mac Polar", "Yankee", " AlphonseHubert", "Kryss-Anthem"));
  $away->add_mid(array("Belegûr", "Annatar", "Melkor", "Phénix"));
  $away->add_att(array("L'Atlante", "Necromancien"));
  $p=new partie($home, $away);
  $p->action(5);
 
 foreach($p->cr as $value) {
  echo "<br />".$value;
 }
?>
Merci.