Jump to content
php.lv forumi

IF madness


anonīms

Recommended Posts

8r97ptxzcmkclll7vqkp.jpg

 

Ideja ir sekojoša.

Ir spēlētājs1 un spēlētājs2, kuriem attiecīgi reitingi tiek atņemti un tad pārbauda kāda ir starpība. Protams šo visu var maukt IF'os, bet es šoreiz no kaut kā tāda gribētu izvairīties, tādēļ gribēju zināt vai ir kāds cits, kārtīgāks variants?

 

Piemērs:

#1 Spēlētājs1 (retings 500) uzvar spēlētāju2( reitings 50), tātad 450 ppunkti starpā un spēlētājs1 saņem 1 reitinga punktu

#2 Spēlētājs2 (reitings 10) uzvar spēlētājs2 (reitings 5) = 5 punkti, tātad spēlētājs1 saņem 15 punktus.

Link to comment
Share on other sites

es mēģinātu uztaisīt tabulu: 

from  to  winHigh  winLow

0     30  15       15
31    60  14       16
61    90  13       17
...

kur from, to - intervāls, winHigh - punktu skaits ja vinnē stiprākais, winLow - ja vinnē vajākais

starpību ņemtu ka absolūto vertību un ja + ņemtu winHight, ja - winLow kolonnu.

 

vai nu

 

from  to  win
...    
-91   -60 17
-61   -30 16      
-31   0   15   
0     30  15       
31    60  14      
61    90  13   
...

un selektē pēc reitingu starpības



 

Link to comment
Share on other sites

$dif = abs(-150);
echo 15 - floor((abs($dif - 1)/30));
echo '<br>';
echo 15 + floor((abs($dif - 1)/30));

kur $diff - reitingu starpība.

Un atsevišķu apstrādi kad $dif > 450

 

p.s. tomēr matemātika ir vajadzīga http://php.lv/f/topic/18967-par-programmetajiem/page-2#entry147529

Edited by php newbie
Link to comment
Share on other sites

labi, pierunāts. Parunājos un turpināsim tomēr izmantot elo, bet rezultātu vēl /4 izdalīsim 

Edit;

 

 

Array
(
[R3] => 977
[R4] => 923
[s1] => 5
[s2] => 4
[R1] => 900
[R2] => 1000
[P1] => +77
[P2] => -77
)

 

;/ baidi daudz vienīgi sāk ņemt nost, ja tikai 100 punkti starpā, bet abiem viņi ir daudz

Edited by anonīms
Link to comment
Share on other sites

Uzlobotā versiju.

Izmantošu šo :)

 

class elo_calculator 
{ public function rating($S1,$S2,$R1,$R2) 
  { if (empty($S1) OR empty($S2) OR empty($R1) OR empty($R2)) return null; 
    if ($S1!=$S2) { if ($S1>$S2) { $E=60-round(1/(1+pow(10,(($R2-$R1)/400)))*60); $R['R3']=$R1+$E; $R['R4']=$R2-$E; } 
                            else { $E=60-round(1/(1+pow(10,(($R1-$R2)/400)))*60); $R['R3']=$R1-$E; $R['R4']=$R2+$E; }} 
             else { if ($R1==$R2) { $R['R3']=$R1; $R['R4']=$R2; } 
                             else { if($R1>$R2) { $E=(60-round(1/(1+pow(10,(($R1-$R2)/400)))*60))-(120-round(1/(1+pow(10,(($R2-$R1)/400)))*60)); $R['R3']=$R1-$E; $R['R4']=$R2+$E; } 
                                           else { $E=(60-round(1/(1+pow(10,(($R2-$R1)/400)))*60))-(120-round(1/(1+pow(10,(($R1-$R2)/400)))*60)); $R['R3']=$R1+$E; $R['R4']=$R2-$E; }}} 
    $R['S1']=$S1; $R['S2']=$S2; $R['R1']=$R1; $R['R2']=$R2; 
    $R['P1']=((($R['R3']-$R['R1'])>0)?"+".($R['R3']-$R['R1']):($R['R3']-$R['R1'])); 
    $R['P2']=((($R['R4']-$R['R2'])>0)?"+".($R['R4']-$R['R2']):($R['R4']-$R['R2'])); 
	
    $R['P1'] = round($R['P1']/4,0);
    $R['P2'] = round($R['P2']/4,0);
	if($R['P1'] == 0 || $R['P2'] == 0) {
		$R['P1'] = 1;
		$R['P2'] = -1;
	}
    return $R; 
}

 

 

 Array
(
    [R3] => 150
    [R4] => 899940
    [s1] => 5
    [s2] => 4
    [R1] => 90
    [R2] => 900000
    [P1] => 15
    [P2] => -15
)
 
Array
(
    [R3] => 930
    [R4] => 870
    [s1] => 5
    [s2] => 4
    [R1] => 900
    [R2] => 900
    [P1] => 8
    [P2] => -8
)
 Array
(
    [R3] => 1014
    [R4] => 786
    [s1] => 5
    [s2] => 4
    [R1] => 1000
    [R2] => 800
    [P1] => 4
    [P2] => -4
)
Edited by anonīms
Link to comment
Share on other sites

Kas tā par modi gāzt visu vienā lielā nesaprotamā klucī, nedomājot, ka kādam citam iespējams tas būs nākotnē jālabo. Takš vismaz noformatējam kā nākas ...

 

class elo_calculator
{
    public function rating($S1, $S2, $R1, $R2)
    {
        if (empty($S1) || empty($S2) || empty($R1) || empty($R2))
            return null;
        
        if ($S1 != $S2) {
            if ($S1 > $S2) {
                $E = 60 - round(1 / (1 + pow(10, ( ($R2 - $R1) / 400 ))) * 60);
                $R['R3'] = $R1 + $E;
                $R['R4'] = $R2 - $E;
            } else {
                $E = 60 - round(1 / (1 + pow(10, ( ($R1 - $R2) / 400 ))) * 60);
                $R['R3'] = $R1 - $E;
                $R['R4'] = $R2 + $E;
            }
        } else {
            if ($R1 == $R2) {
                $R['R3'] = $R1;
                $R['R4'] = $R2;
            } else {
                if($R1 > $R2) {
                    $E = 60 - round(1 / (1 + pow(10,( ($R1 - $R2) / 400 ))) * 60)) - (120 - round(1 / (1 + pow(10, ( ($R2-$R1)/400 ))) * 60);
                    $R['R3'] = $R1 - $E;
                    $R['R4'] = $R2 + $E;
                } else {
                    $E = 60 - round(1 / (1 + pow(10, ( ($R2-$R1) / 400 ))) * 60)) - (120 - round(1 / (1 + pow(10, ( ($R1-$R2) / 400))) * 60);
                    $R['R3'] = $R1 + $E;
                    $R['R4'] = $R2-$E;
                }
            }
        }
        
        $R['S1'] = $S1;
        $R['S2'] = $S2;
        $R['R1'] = $R1;
        $R['R2'] = $R2;
        
        $R['P1'] = (($R['R3'] - $R['R1']) > 0) ? "+".($R['R3'] - $R['R1']) : ($R['R3'] - $R['R1']);
        $R['P2'] = (($R['R4'] - $R['R2']) > 0) ? "+".($R['R4'] - $R['R2']) : ($R['R4'] - $R['R2']);
    
        $R['P1'] = round($R['P1'] / 4, 0);
        $R['P2'] = round($R['P2'] / 4, 0);
    
        if($R['P1'] == 0 || $R['P2'] == 0) {
            $R['P1'] = 1;
            $R['P2'] = -1;
        }
        
        return $R;
    }
}

Šādi nav mazliet saprotamāk un vieglāk rediģējami?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...