Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ Mr. Queen is a chess engine written in C.
* Unaware of draw by repetition.
* Basic evaluation includes only material and piece-square values.

#### Usage
* Use 'make' to build the program as is. This program gives you access to the UCI implementation.
* When implementing your own programs, you can create objects of the different parts.
..* For example, if you need to create a board you can use 'Board board;'
..* Then you can use the functions in board.c such as 'board_print(&boar);'

---
##Examples

###2PlayerNoFeatures
As the name suggests, this implemntation is of a chess game with 2 players but with absolutely no features. That means, the users have to account for everything including castling, checkmates, promotions, captures etc.

It is inteded to give you a basic understanding of how to use the library in an actual program.

####Usage
Navigate into the examples folder. Then, in your command line, use the 'make' command to build the program.

<p align="center"><img src="http://i.imgur.com/oiWiEvK.png"></p>
81 changes: 81 additions & 0 deletions examples/2PlayerNoFeatures/2PlayerNoFeatures.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#include "2PlayerNoFeatures.h"


int main(int argc, char **argv) {
print_commands();

//Initialize game variable
Board board;
int currentPlayer = 1;


//Initiallize game
board_reset(&board);
board_print(&board);

while(1){
int currentRoundEnd = play_round(currentPlayer, &board);
if(currentRoundEnd == 1){
return 0;
}else{
currentPlayer = currentPlayer == 1? 2: 1;
}
}
return 0;
}

int play_round(int currentPlayer, Board *board)
{
string s = malloc(sizeof(char)*5);
while(1){
printf("Player %i: ", currentPlayer);
scanf("%s", s);
lower(&s);
int playerChoiceResult = handle_player_choice(board, s);
if(playerChoiceResult == 0 || playerChoiceResult == 1) {return playerChoiceResult;}
}
free(s);
}

int handle_player_choice(Board *board, string s){
if(strcmp(s, "quit") == 0){
return 1;
} else if(strcmp(s, "show") == 0){
board_print(board);
return -1;
} else if (strcmp(s, "help" == 0)){
print_commands();
return -1;
} else{
process_move(board, s);
return 0;
}
}

void process_move(Board *board, string s){
const string moveString = s;
Move move;
printf("MOVE:%s\n", s);
move_from_string(&move, moveString);
make_move(board, &move);
board_print(board);
}

void lower(char **s){
char *temp = *s;
int slen = strlen(*s);
char tempHolder[slen];
for(int i = 0; i < slen; i++){
tempHolder[i] = tolower(temp[i]);
}
*s = tempHolder;
}

void print_commands(void){
printf(
"-Type help to get this list of commands.\n"
"-To make a move, type your move in long algebraic notation.\n"
"-To See the board in it\'s current state, type show. \n"
"-To quit the program, type quit\n"
);
}
15 changes: 15 additions & 0 deletions examples/2PlayerNoFeatures/2PlayerNoFeatures.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "../../src/board.h"
#include "../../src/move.h"
#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#define string char *

void print_commands(void);
int play_round(int currentPlayer, Board *board);
void lower(char **s);
int handle_player_choice(Board *board, string s);
void process_move(Board *board, string s);
9 changes: 9 additions & 0 deletions examples/2PlayerNoFeatures/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#Examples

##2PlayerNoFeatures
As the name suggests, this implemntation is of a chess game with 2 players but with absolutely no features. That means, the users have to account for everything including castling, checkmates, promotions, captures etc.

It is inteded to give you a basic understanding of how to use the library in an actual program.

###Usage
Navigate into the examples folder. Then, in your command line, use the 'make' command to build the program.
12 changes: 12 additions & 0 deletions examples/2PlayerNoFeatures/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CC=gcc
CFLAGS=-I.
DEPS = ../../src/board.c ../../src/move.c ../../src/gen.c ../../src/bb.c ../../src/util.c

%.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)

2PlayerNoFeatures : 2PlayerNoFeatures.c
$(CC) $(CFLAGS) 2PlayerNoFeatures.c -o 2PlayerNoFeatures $(DEPS)

clean:
rm 2PlayerNoFeatures