It is a platform for bots to compete against each other in various games, both contrived and common, to test each programmer's ability to write algorithmic and logical code.
You can use absolutely any language. However, the API has currently only been written for Java, Python and C/Windows. Rewriting it for other languages and OS's is necessary. If you'd like to help me, please do so.
Currently, the only supported game is:
You simply write an AI that can play as one of the players in any of the games on the platform. You run the AI on your computer, and have the code call the functions in the CB API. Calling these functions will automatically make it play against other AIs in real-time.
The purpose of this is to challenge yourself, practice general and specific coding skills, learn more about algorithms and AIs, and have fun.
After you bind your AI to the API, you will see the results of all your matches updated real-time on this website. You will also be ranked against every other bot who's played the same game in a variety of ways. This can help you track your progress as a programmer on Coders Block, set personal goals, and compare yourself to others.
The API is limited to only the necessary commands. They are all described as follows for the C/Windows API. There will be slight variations for each language. See the examples at the bottom.
API In C For Windows (Note: Must Add "-lwsock32" To Your Linker)
API In Python For All OS's (Note: Must Rename File To "cbapi.py")
API In Java For All OS's * (Note: Must Add The Line "import net.codersblock.api.CodersBlock;")
* Many thanks to andro for the Java Implementation of the CB API.
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include "cbapi.h"
void delay(int sec) {
Sleep(sec*1000);
printf(".");
}
int main() {
char *reply;
cb_init(0);
cb_login("Sane", "************", "TIC-TAC-TOE");
if( strcmp(reply = cb_cmd("CHECK"), "OKAY") ) {
printf(reply);
return cb_cleanup();
}
printf("Looking For Game ...");
while( strcmp(reply = cb_cmd("GETGAME"), "WAIT") == 0 ) delay(5);
if( !reply ) return cb_cleanup()
printf("\nPlaying Against \"%s\"\n", reply);
while(1) {
printf("Waiting For Turn ...");
while( strcmp(reply = cb_cmd("GETBOARD"), "WAIT") == 0 ) delay(0);
if( !reply ) return cb_cleanup()
if( strcmp(reply, "WIN") == 0 || strcmp(reply, "LOSE") == 0 || strcmp(reply, "TIE") == 0 ) {
printf("Game Over: %s\n", reply);
return cb_cleanup();
}
/* Make Move By Updating One Of The Pieces In 'reply' */
if( strcmp(reply = cb_cmd(reply), "OKAY") ) {
printf("Disqualified For Illegal Move Or Timed Out\n");
return cb_cleanup();
}
else printf("Made Move\n");
}
return cb_cleanup();
}
import cbapi
cb = cbapi.init(0)
cb.login("Sane", "************", "TIC-TAC-TOE")
if (cb.cmd("CHECK") != "OKAY"):
print "Invalid Login"
cb.cleanup()
import net.codersblock.api.CodersBlock;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
new Main();
}
public Main() {
CodersBlock cb = new CodersBlock();
cb.login("java_api_test", "apitest", "TIC-TAC-TOE");
if (!cb.cmd("CHECK").equals("OKAY"))
System.out.println("Invalid login");
Scanner s = new Scanner(System.in);
while (true) {
System.out.print("Enter command: ");
String cmd = s.nextLine();
String response = cb.cmd(cmd);
System.out.println("Server: " + response);
}
}
}