chesslablab/chess-server

Update the ELO of the players

Closed this issue · 1 comments

Given two usernames and a game result after a match, the ChessServer\Command\Data\EloCommand will calculate the new ELO for both players updating the users table accordingly.

See chesslablab/chess-data#36

After some thought, the ELO update needs to be implemented in the res() method in ChessServer\Command\Game\Mode\PlayMode

<?php

namespace ChessServer\Command\Game\Mode;

// ...

class PlayMode extends AbstractMode
{
    // ...

    public function res($params, $cmd)
    {
        switch (get_class($cmd)) {
            case PlayLanCommand::class:
                $isValid = $this->game->playLan($params['color'], $params['lan']);
                $this->updateTimer($params['color']);
                if ($this->game->state()->end) {
                    // TODO ...
                }
                return [
                    $cmd->name => [
                      ... (array) $this->game->state(),
                      'variant' =>  $this->game->getVariant(),
                      // play mode information
                      'timer' => $this->timer,
                      'isValid' => $isValid,
                    ],
                ];

            default:
                return parent::res($params, $cmd);
        }
    }
}