The Instigator
larztheloser
Pro (for)
Winning
18 Points
The Contender
ADreamOfLiberty
Con (against)
Losing
0 Points

Programming competition

Do you like this debate?NoYes+1
Add this debate to Google Add this debate to Delicious Add this debate to FaceBook Add this debate to Digg  
Post Voting Period
The voting period for this debate has ended.
after 4 votes the winner is...
larztheloser
Voting Style: Open Point System: 7 Point
Started: 2/21/2014 Category: Miscellaneous
Updated: 3 years ago Status: Post Voting Period
Viewed: 894 times Debate No: 45978
Debate Rounds (2)
Comments (7)
Votes (4)

 

larztheloser

Pro

Welcome one and all to the programming competition between myself and ADreamOfLiberty!

The rules are simple. ADreamOfLiberty shall make an AI capable of playing chess with the white pieces. I shall make an AI for the black pieces. Voters will play the AIs off against each other and vote for whoever's AI wins in their game. Games are played with 5-min per side time controls in an engine I wrote and ADreamOfLiberty checked, based on chess.js and chessboard.js. Both of us will write our AIs in javascript (with web workers) which will work with any modern browser.

RULES

1. This debate must be accepted within 1 hour of midnight GMT on the 22nd of February. Failure to accept within a 1 hour approximate leeway will mean con's instant disqualification.

2. In the first round con must provide a link to his .js file. He may optionally describe his AI in this round. Please note that we only have 1 hour each side to post.

3. In the second round pro must provide a link to a site where voters can test both his and his opponent's AI scripts against each other as described above. Con may do what he pleases in this round and it will not count against him if he forfeits that round.

4. Both of us will begin programming our AIs on the 18th of February, again at midnight GMT. While there is no formal check for this, we can basically both be honest.

5. Any plagiarisation of source code from other projects will mean an instant disqualification.

6. All AIs should be written in javascript. No other languages will be permitted.

7. In the event of a draw, voters should refresh the page to give both AIs a rematch until a winner can be found.

8. If there are any rule issues or clarifications these must be bought up in the comments sufficiently before the 18th to allow time to resolve them before the competition begins.

Without further ado I wish my opponent the best of luck and look forward to a fun competition!
ADreamOfLiberty

Con

Well, this piece of crap can't consistently beat the demo. I want to apologize to my opponent for putting up such junk against his; and if this thing beats his I am going to look like an a$$hole but I really doubt that will be the case. I plead laziness. I wrote this in the last two hours and spend 1:30 of that trying to figure out why chrome stopped letting me debug a web worker...

Place this in a js file in the ai folder, going to have to change the index to match. Voters can get the folders from my opponent because he has it hosted and really don't want to go through the trouble of creating an anonymous transfer method.

/*
Chess AI thing, ADreamOfLiberty http://www.debate.org...

For: http://www.debate.org...
*/
importScripts('../js/chess.min.js');

var timeLeft = 5 * 60000;
var numberOfMovesLeft = 120;
var game;

onmessage = function (evt)
{
var timeWhenCalled = new Date().getTime();
var timeToThink = calculateTimeToThink();

fen = evt.data;
game = new Chess(fen);
possibleMoves = game.moves({ verbose: true });
evaluatedMoves = new Array(possibleMoves.length);
highestValueIndex = Math.floor(Math.random() * possibleMoves.length);
highestValue = 0;

//Initial evaluation
for (var i = 0; i < possibleMoves.length; i++)
{
evaluatedMoves[i] = evaluateMove(possibleMoves[i]);

if (evaluatedMoves[i].value > highestValue)
{
highestValue = evaluatedMoves[i].value;
highestValueIndex = i;
}
}

//Refine with predictions
var index = 0;
while ((new Date().getTime() - timeWhenCalled) < timeToThink)
{
if (evaluatedMoves[index] == null)
{
var oops;
}
makePredictions(evaluatedMoves[index]);

if (evaluatedMoves[index].value > highestValue)
{
highestValue = evaluatedMoves[index].value;
highestValueIndex = index;
}

index++;
if (index >= evaluatedMoves.length)
{
break;
}
}

numberOfMovesLeft -= 1;

var timeUsedUp = new Date().getTime() - timeWhenCalled;
timeLeft -= timeUsedUp;

postMessage(evaluatedMoves[highestValueIndex].move);
};

//Values
/*PawnValue = { FENCharacter: "P", Value: 10 };
KnightValue = { FENCharacter: "N", Value: 30 };
BishopValue = { FENCharacter: "B", Value: 50 };
RookValue = { FENCharacter: "R", Value: 50 };
QueenValue = { FENCharacter: "Q", Value: 100 };
KingValue = { FENCharacter: "K", Value: 100000 };*/

var Values = {"p" : 10, "n" : 30, "b" : 50, "r" : 50, "q" : 100, "k" : 100000};

//Example evaluated move:
// {value : 10, move: "d5", prediction : {state : Chess instance, moves: [recursive evaluated move entries]}}

function evaluateMove(move)
{
var value = 0;

if (move.flags.indexOf("c") != -1)
{
value = Values[move.captured];
}

return { value: value, move: move.san };
}

function makePredictions(evaluatedMove)
{
var currentChessContext = new Chess(game.fen());
var san = evaluatedMove.move
currentChessContext.move(san);

//At this point it is the enemies turn, so here the value is negative because we don't want them to capture us.

var predictedPossibleMoves = currentChessContext.moves({ verbose: true });
var predictedEvaluatedMoves = new Array(predictedPossibleMoves.length);
var highestIndex = 0;
var highestValue = 0;

for (var i = 0; i < predictedPossibleMoves.length; i++)
{
predictedEvaluatedMoves[i] = evaluateMove(predictedPossibleMoves[i]);
evaluatedMove.value -= predictedEvaluatedMoves[i].value * 1.2;

if (predictedEvaluatedMoves[i].value > highestValue)
{
highestIndex = i;
}

}

if (predictedEvaluatedMoves[highestIndex] != null) {
//Look one more
currentChessContext.move(predictedEvaluatedMoves[highestIndex].move.san);

//At this point it is the our turn again

var predictedPossibleMoves = currentChessContext.moves({ verbose: true });
var predictedEvaluatedMoves = new Array(predictedPossibleMoves.length);

for (var i = 0; i < predictedPossibleMoves.length; i++) {
predictedEvaluatedMoves[i] = evaluateMove(predictedPossibleMoves[i]);
evaluatedMove.value += predictedEvaluatedMoves[i].value * 0.8;
}
}
}

function calculateTimeToThink()
{
if (numberOfMovesLeft <= 5)
{
return timeLeft / 25;
}
else
{
return timeLeft / numberOfMovesLeft;
}
}
Debate Round No. 1
larztheloser

Pro

I thank my opponent for participating!

Here you can see my AI square off against his. Mine plays black, his plays white:

http://lynkd.co.nz...

Voting Instructions

1. Open the URL (http://lynkd.co.nz...)
2. Thrill as both AIs finish their game
3. Vote in this debate for whoever's AI won (if white wins, vote for my opponent, if black vote for me)

Thank you so much in advance for everyone who takes a moment to vote on this!

Final Notes

For fun, here you can see mine playing white and his black: http://lynkd.co.nz...

You can also play a game yourself against my AI at http://lynkd.co.nz... . It's not that strong but it's fun anyway.

My AI exposes its thinking to the javascript console in browsers that support that for web workers, telling you what moves it is anticipating to come next and how much it is liking its current position with every move.

I thank my opponent for a fun challenge and wish him the best of luck in his future programming endeavors.
Debate Round No. 2
7 comments have been posted on this debate. Showing 1 through 7 records.
Posted by Romanii 3 years ago
Romanii
I lost against your simulator :(
Posted by larztheloser 3 years ago
larztheloser
Real shame you can't access it. Basically my AI thinks around 15 times longer than yours. Here's some quick games I just played for you:

1.h4 e5 2.a4 c5 3.g4 f6 4.Ra3 d5 5.c3 Qa5 6.Nf3 Bxg4 7.Nxe5 fxe5 8.Ra1 b6 9.Rh3 h5 10.Ra2 a6 11.Rh1 g6 12.Bg2 Ne7 13.Bxd5 Nxd5 14.e3 Bxd1 15.Kxd1 b5 16.axb5 Qxa2 17.bxa6 Nxa6 18.c4 Nf6 19.f3 O-O-O 20.b4 cxb4 21.c5 Bxc5 22.Ke2 b3 23.Kf1 Bxe3 24.dxe3 Rd1#

1.d4 e5 2.dxe5 g5 3.Bxg5 Qxg5 4.Qxd7+ Bxd7 5.Nf3 Qc1#

1.Na3 d5 2.g3 a5 3.Bg2 Be6 4.Bxd5 Qxd5 5.Nb5 Qxh1 6.Nxc7+ Kd8 7.Nxa8 Qxg1#

1.Nh3 d5 2.c3 Qd6 3.d4 Bg4 4.Qa4+ c6 5.Qxa7 Rxa7 6.Na3 h6 7.Bxh6 Nxh6 8.b4 Rxa3 9.f4 Rxc3 10.a4 Qxb4 11.g3 f5 12.Rg1 e6 13.Ra3 Rc1+ 14.Kf2 Qxa3 15.e4 Qf3#

1.g3 e5 2.h4 c5 3.d3 d5 4.Bd2 Bg4 5.Rh3 Qd7 6.Bg5 h5 7.Nf3 Bxh3 8.Bxh3 Qd6 9.Nxe5 f6 10.Bxf6 Nxf6 11.Qd2 a5 12.Qxa5 Qxe5 13.Qxa8 Qxe2+ 14.Kxe2 Bd6 15.Qxb8+ Bxb8 16.d4 cxd4 17.c3 Ba7 18.cxd4 Bxd4 19.Bd7+ Nxd7 20.Kf3 Bxb2 21.a4 Bxa1 22.g4 O-O+ 23.Ke2 hxg4 24.f3 gxf3+ 25.Ke1 f2+ 26.Ke2 d4 27.h5 f1=Q+ 28.Kd2 Rf2#

I wonder if you can somehow access just my script directly? It's at http://lynkd.co.nz... - then you can see for yourself.
Posted by ADreamOfLiberty 3 years ago
ADreamOfLiberty
So how bad was it?
Posted by ADreamOfLiberty 3 years ago
ADreamOfLiberty
It's probably the way I'm trying to get to it. Don't worry about it, staying anonymous screws up a lot of things for me.
Posted by larztheloser 3 years ago
larztheloser
You can't run it? That could be a engine bug.

What browser are you using? Are any error messages displayed?
Posted by ADreamOfLiberty 3 years ago
ADreamOfLiberty
Well I can't seem to run it, going to have to trust voters.
Posted by larztheloser 3 years ago
larztheloser
ALSO - in the event of a draw, voters, refresh the page for a new game.
4 votes have been placed for this debate. Showing 1 through 4 records.
Vote Placed by Krazzy_Player 3 years ago
Krazzy_Player
larztheloserADreamOfLibertyTied
Agreed with before the debate:--Vote Checkmark0 points
Agreed with after the debate:--Vote Checkmark0 points
Who had better conduct:--Vote Checkmark1 point
Had better spelling and grammar:--Vote Checkmark1 point
Made more convincing arguments:Vote Checkmark--3 points
Used the most reliable sources:--Vote Checkmark2 points
Total points awarded:30 
Reasons for voting decision: Black won thus voting in favour of Pro.
Vote Placed by TUF 3 years ago
TUF
larztheloserADreamOfLibertyTied
Agreed with before the debate:--Vote Checkmark0 points
Agreed with after the debate:--Vote Checkmark0 points
Who had better conduct:--Vote Checkmark1 point
Had better spelling and grammar:--Vote Checkmark1 point
Made more convincing arguments:Vote Checkmark--3 points
Used the most reliable sources:--Vote Checkmark2 points
Total points awarded:30 
Reasons for voting decision: As per voting instructions, larz has won.
Vote Placed by imabench 3 years ago
imabench
larztheloserADreamOfLibertyTied
Agreed with before the debate:--Vote Checkmark0 points
Agreed with after the debate:--Vote Checkmark0 points
Who had better conduct:Vote Checkmark--1 point
Had better spelling and grammar:Vote Checkmark--1 point
Made more convincing arguments:Vote Checkmark--3 points
Used the most reliable sources:Vote Checkmark--2 points
Total points awarded:70 
Reasons for voting decision: Black won pretty fast in the one I watched
Vote Placed by Josh_b 3 years ago
Josh_b
larztheloserADreamOfLibertyTied
Agreed with before the debate:--Vote Checkmark0 points
Agreed with after the debate:--Vote Checkmark0 points
Who had better conduct:--Vote Checkmark1 point
Had better spelling and grammar:--Vote Checkmark1 point
Made more convincing arguments:Vote Checkmark--3 points
Used the most reliable sources:Vote Checkmark--2 points
Total points awarded:50 
Reasons for voting decision: Black won on the game that I watched.