Computer Chess Club Archives


Search

Terms

Messages

Subject: Ah, bummer. Bug.

Author: Tom Kerrigan

Date: 14:32:18 01/19/02

Go up one level in this thread


Stupid bug with calculating the Buchhalz points. (Hopefully) correct standings
and source below.

Place  Program        Points  Buch.
   1.  ban            2.0     1.0
       SearcherX      2.0     1.0
   3.  pharaon        2.0     0.0
       diep           2.0     0.0
       TaoYin         2.0     0.0
       X-Engine       2.0     0.0
   7.  Yace           1.5     1.0
       BK-Chess       1.5     1.0
       sherifk        1.5     1.0
       DeepFritz      1.5     1.0
  11.  ChesterX       1.5     0.0
       TombRaider     1.5     0.0
       gambitmaster   1.5     0.0
       PostModernist  1.5     0.0
       WarpX          1.5     0.0
  16.  Somnus         1.0     2.0
       Butcher        1.0     2.0
  18.  KingKings      1.0     1.5
       QuarkX         1.0     1.5
       Chezzz         1.0     1.5
       Aristarch      1.0     1.5
  22.  JZInsomniac    1.0     1.0
       ArasanX        1.0     1.0
       Hossa          1.0     1.0
       crafty         1.0     1.0
       Esc            1.0     1.0
       CyberPagno     1.0     1.0
       monsoon        1.0     1.0
       Ferret-CCT     1.0     1.0
       SandmanJr      1.0     1.0
       Hiarcs8x       1.0     1.0
       Leila          1.0     1.0
       IsiChess       1.0     1.0
  34.  ZarkovX        1.0     0.5
  35.  Sjeng          1.0     0.0
  36.  Amateur        0.5     1.0
  37.  AvernoX        0.0     2.0
       PolarChess     0.0     2.0
       QALAT          0.0     2.0
       djenghis       0.0     2.0
  41.  Lordx          0.0     1.5
       Celes          0.0     1.5
       Tinker         0.0     1.5
       nullmover      0.0     1.5
       pyotr          0.0     1.5
  46.  Armageddon     0.0     1.0





#include <stdio.h>
#include <memory.h>
#include <string.h>

typedef struct {
	char name[100];
	float score;
	int opp[100];
	int opps;
	float buch;
} player_t;

player_t player[100];
int players = 0;
FILE *pgn;

int grab_player(char *line)
{
	char name[256];
	int i, j = 0;
	for (i = 0; line[i] != '\"'; ++i);
	for (++i; line[i] != '\"'; ++i)
		name[j++] = line[i];
	name[j] = 0;
	for (i = 0; i < players; ++i)
		if (!strcmp(name, player[i].name))
			return i;
	strcpy(player[players].name, name);
	player[players].score = 0.0;
	player[players++].buch = 0.0;
	return players - 1;
}

void select_sort(int s)
{
	int i;
	float fake_score;
	float best_score = -1.0;
	int best_i;
	player_t t;

	for (i = s; i < players; ++i) {
		fake_score = player[i].score + (player[i].buch / 1000);
		if (fake_score > best_score) {
			best_score = fake_score;
			best_i = i;
		}
	}
	t = player[s];
	player[s] = player[best_i];
	player[best_i] = t;
}

void print_results()
{
	int i;

	printf("Place  Program        Points  Buch.\n");
	for (i = 0; i < players; ++i) {
		if (i != 0 &&
				player[i].score == player[i - 1].score &&
				player[i].buch == player[i - 1].buch)
			printf("       ");
		else
			printf("%4d.  ", i + 1);
		printf("%-13s  %-6.1f  %-5.1f\n",
				player[i].name, player[i].score, player[i].buch);
	}
}

int main()
{
	char line[256];
	int white, black, i, j;

	pgn = fopen("games.pgn", "r");
	for (;;) {
		if (!fgets(line, 256, pgn))
			break;
		if (strstr(line, "[White \""))
			white = grab_player(line);
		if (strstr(line, "[Black \""))
			black = grab_player(line);
		if (strstr(line, "[Result \"")) {
			player[white].opp[player[white].opps++] = black;
			player[black].opp[player[black].opps++] = white;
			if (strstr(line, "1-0"))
				player[white].score += 1.0;
			else if (strstr(line, "1/2-1/2")) {
				player[white].score += 0.5;
				player[black].score += 0.5;
			}
			else
				player[black].score += 1.0;
		}
	}
	fclose(pgn);
	for (i = 0; i < players; ++i)
		for (j = 0; j < player[i].opps; ++i)
			player[i].buch += player[player[i].opp[j]].score;
	for (i = 0; i < players; ++i)
		select_sort(i);
	print_results();
	return 0;
}



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.