3

I am a complete new starter in programming. I just made a system for personal use. There is a possibility to add sports match results of two players.

So far everything works fine. Now I am thinking to add an ELO rating system.

I can not understand, how should I design my database.

Problem is, that I can not understand, how to keep correct record of rating calculation in case if any game result will be deleted at any time. For example, somebody will add faulty data and game entry should be deleted.

So, how should the database design be made, that if I will delete any game from the middle of entries, the rating will recalculate correctly?

an illustrative example of my problem, i can not solve (rating calculation just informative):

 Player1 (rating 1200), Player2 (1200)
 Game1 played, player1 wins.
 Rating after game: P1:1231, P2:1169
 Game2 played, Player1 wins.
 Rating: P1:1259, P2:1141
 Game3, Player2 wins
 Rating: P1:1220, P2:1180

So, then I realize, that game 2 has false data, I want to delete it.

What should happen? I delete game2, then the script should alter the rating like Grab rating of both players from one game before, from after game1. which would be P1:1231, P2: 1169 And then recalculate all rating after the deleted game. So Game3, player wins, rating should be P1:1198, P2:1202

I can not just delete game2 and it's rating differences... rating has to be recalculated from the previous game and for all after games played.

More complicated it gets if there are 3 or more players, and they have played games after the one I want to delete. Because of their ratings have changed. And if a game is deleted, then all rating changes of games played after should have be recalculated one by one.

I hope my problem is clear...

So thew question is, could you please give me, a complete starter of php/.mysql a hints of what should be the logic of database and process of calculating the ratings for my situation.

Thanks in advance.

Isaac G Sivaa
  • 1,289
  • 4
  • 15
  • 32
OGlv
  • 31
  • 2
  • Mark, I am sorry I was not completely clear with my question. Question is - would you be able to help me with any hint of how should I try to design my database? Currently I have a players table and a games table. How should I implement the ratings data? Should it be a new table or any other how... I can not figure it out, how should I organize my data in database... My knowledge of mysql/php possibilities is too low. I need some help from a side. I thought this is a place to ask for such advices. – OGlv Sep 25 '14 at 16:31
  • @MarcB: they don't want us to design the complete system. They asked for hints and advices. There's nothing wrong about that. – georg Sep 25 '14 at 16:40

1 Answers1

1

Basically, there will be two tables: players(name,whatever else,rating) and games(player_id_white,player_id_black,result=1,0,-1,date).

After a game has been deleted, reset all players' ratings back to the initial value and recalculate them from scratch. Just read the games table sorted by date, update ratings in memory and finally write them back to the players table.

This is somehow straightforward and crude solution, but should work for you unless (until) you have thousands of players and millions of games.

georg
  • 211,518
  • 52
  • 313
  • 390