initial commit
This commit is contained in:
commit
61aa14398a
15 changed files with 4628 additions and 0 deletions
69
players/example-player.cc
Normal file
69
players/example-player.cc
Normal file
|
@ -0,0 +1,69 @@
|
|||
/* -*- Mode: C -*- */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mcp.h>
|
||||
|
||||
static int
|
||||
send_move(int row, int col)
|
||||
{
|
||||
FILE *f = fdopen(dup(CHILD_OUT_FD), "w");
|
||||
fprintf(f, "%u,%u", row, col);
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
read_move_from_user(int *row, int *col)
|
||||
{
|
||||
char input[128];
|
||||
|
||||
do {
|
||||
printf("Zug (<Zeile>,<Spalte>): "); fflush(stdout);
|
||||
if (fgets(input, sizeof(input), stdin) == NULL) abort();
|
||||
} while((sscanf(input, "%u,%u", row, col) != 2) ||
|
||||
(*row > 8) || (*col > 8));
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int done = 0;
|
||||
int turn_row, turn_col;
|
||||
|
||||
while (!done) {
|
||||
/* BEGIN PLAYER-SPECIFIC CODE */
|
||||
|
||||
// 1. Read state
|
||||
char state_buffer[128];
|
||||
ssize_t bytes = read(CHILD_IN_FD, state_buffer, sizeof(state_buffer));
|
||||
if (bytes != 65) // invalid number of chars
|
||||
abort();
|
||||
|
||||
// state_buffer enthält jetzt 65 Zeichen ('.' oder 'X' oder 'O'):
|
||||
// * Das ERSTE Zeichen gibt an, welcher Spieler an der Reihe ist.
|
||||
// * Die weiteren 64 Zeichen definieren die Belegung des Feldes.
|
||||
// * Die Belegung wird reihenweise gegeben, d.h. die Zeichen
|
||||
// 1 bis 8 definieren die erste Zeile des Feldes, Zeichen 9 bis 17
|
||||
// geben die zweite Zeile usw.
|
||||
// * X und O stehen hierbei für die jeweiligen Spieler. Leere Felder
|
||||
// sind durch einen Punkt (.) gekennzeichnet.
|
||||
|
||||
// 2. Input move
|
||||
read_move_from_user(&turn_row, &turn_col);
|
||||
|
||||
// 3. Return result
|
||||
send_move(turn_row, turn_col);
|
||||
|
||||
/* END PLAYER-SPECIFIC CODE */
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* EOF */
|
57
players/my-player.cc
Normal file
57
players/my-player.cc
Normal file
|
@ -0,0 +1,57 @@
|
|||
/* -*- Mode: C -*- */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mcp.h>
|
||||
|
||||
static int
|
||||
send_move(int row, int col)
|
||||
{
|
||||
FILE *f = fdopen(dup(CHILD_OUT_FD), "w");
|
||||
fprintf(f, "%u,%u", row, col);
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int done = 0;
|
||||
|
||||
while (!done) {
|
||||
int turn_row = 0;
|
||||
int turn_col = 0;
|
||||
/* BEGIN PLAYER-SPECIFIC CODE */
|
||||
|
||||
// 1. Read state
|
||||
char state_buffer[128];
|
||||
ssize_t bytes = read(CHILD_IN_FD, state_buffer, sizeof(state_buffer));
|
||||
if (bytes != 65) // invalid number of chars
|
||||
abort();
|
||||
|
||||
// state_buffer enthält jetzt 65 Zeichen ('.' oder 'X' oder 'O'):
|
||||
// * Das ERSTE Zeichen gibt an, welcher Spieler an der Reihe ist.
|
||||
// * Die weiteren 64 Zeichen definieren die Belegung des Feldes.
|
||||
// * Die Belegung wird reihenweise gegeben, d.h. die Zeichen
|
||||
// 1 bis 8 definieren die erste Zeile des Feldes, Zeichen 9 bis 17
|
||||
// geben die zweite Zeile usw.
|
||||
// * X und O stehen hierbei für die jeweiligen Spieler. Leere Felder
|
||||
// sind durch einen Punkt (.) gekennzeichnet.
|
||||
|
||||
// 2. TODO: Strategie hier einfügen. Resultat in turn_row und turn_col speichern.
|
||||
|
||||
// 3. Return result
|
||||
send_move(turn_row, turn_col);
|
||||
|
||||
/* END PLAYER-SPECIFIC CODE */
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* EOF */
|
15
players/playerlib.cc
Normal file
15
players/playerlib.cc
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "playerlib.h"
|
||||
|
||||
char getEnemyChar(char ownc)
|
||||
{
|
||||
char enemyc;
|
||||
switch(ownc){
|
||||
case "O": enemyc="X"; break;
|
||||
case "X": enemyc="O";
|
||||
}
|
||||
return enemyc;
|
||||
}
|
||||
|
8
players/playerlib.h
Normal file
8
players/playerlib.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef PLAYERLIB_H
|
||||
#define PLAYERLIB_H
|
||||
char enemyc = 0;
|
||||
|
||||
//returns the character used for the enemy's stones
|
||||
char getEnemyChar(char);
|
||||
|
||||
#endif
|
62
players/random-player.cc
Normal file
62
players/random-player.cc
Normal file
|
@ -0,0 +1,62 @@
|
|||
/* -*- Mode: C -*- */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mcp.h>
|
||||
|
||||
#include "playerlib.h"
|
||||
|
||||
static int
|
||||
send_move(int row, int col)
|
||||
{
|
||||
FILE *f = fdopen(dup(CHILD_OUT_FD), "w");
|
||||
fprintf(f, "%u,%u", row, col);
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int done = 0;
|
||||
|
||||
while (!done) {
|
||||
int turn_row = 0;
|
||||
int turn_col = 0;
|
||||
/* BEGIN PLAYER-SPECIFIC CODE */
|
||||
|
||||
// 1. Read state
|
||||
char state_buffer[128];
|
||||
ssize_t bytes = read(CHILD_IN_FD, state_buffer, sizeof(state_buffer));
|
||||
if (bytes != 65) // invalid number of chars
|
||||
abort();
|
||||
|
||||
// state_buffer enthält jetzt 65 Zeichen ('.' oder 'X' oder 'O'):
|
||||
// * Das ERSTE Zeichen gibt an, welcher Spieler an der Reihe ist.
|
||||
// * Die weiteren 64 Zeichen definieren die Belegung des Feldes.
|
||||
// * Die Belegung wird reihenweise gegeben, d.h. die Zeichen
|
||||
// 1 bis 8 definieren die erste Zeile des Feldes, Zeichen 9 bis 17
|
||||
// geben die zweite Zeile usw.
|
||||
// * X und O stehen hierbei für die jeweiligen Spieler. Leere Felder
|
||||
// sind durch einen Punkt (.) gekennzeichnet.
|
||||
|
||||
// 2. TODO: Strategie hier einfügen. Resultat in turn_row und turn_col speichern.
|
||||
if(!enemyc)
|
||||
enemyc = getEnemyChar(state_buffer[0]);
|
||||
printf("%s",enemyc);
|
||||
|
||||
// 3. Return result
|
||||
//send_move(turn_row, turn_col);
|
||||
|
||||
/* END PLAYER-SPECIFIC CODE */
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* EOF */
|
13
players/tags
Normal file
13
players/tags
Normal file
|
@ -0,0 +1,13 @@
|
|||
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
|
||||
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
|
||||
!_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/
|
||||
!_TAG_PROGRAM_NAME Exuberant Ctags //
|
||||
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
|
||||
!_TAG_PROGRAM_VERSION 5.8 //
|
||||
main example-player.cc /^int main(void)$/;" f
|
||||
main my-player.cc /^int main(void)$/;" f
|
||||
main random-player.cc /^int main(void)$/;" f
|
||||
read_move_from_user example-player.cc /^read_move_from_user(int *row, int *col)$/;" f file:
|
||||
send_move example-player.cc /^send_move(int row, int col)$/;" f file:
|
||||
send_move my-player.cc /^send_move(int row, int col)$/;" f file:
|
||||
send_move random-player.cc /^send_move(int row, int col)$/;" f file:
|
Loading…
Add table
Add a link
Reference in a new issue