Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#26 2008-03-29 04:30:43

LuisRodg
Real Member
Registered: 2007-10-23
Posts: 322

Re: Chess

Could you please add different levels of difficulty?

Look at this game in pgn-viewer:

1: e4  Nc6
2: f4  Nf6
3: Nc3  d6
4: Nf3  Be6
5: d4  h5
6: d5  Nxd5
7: exd5  Bxd5
8: Qxd5  Nb4
9: Qb5+  c6
10: Qxb4  c5
11: Bb5+  Qd7
12: Bxd7+  Kxd7
13: Qxb7+  Ke8
14: Nb5  Rd8
15: Qc6+  Rd7
16: Qc8+  Rd8
17: Nc7++

in move 5-6 it let me fork one of his pieces but instead of losing just that one, it ate with the knight which ended up losing 2 pieces. It went and gave me another piece later on.

Also, when a move gives checkmate, such as in my example "17: Nc7+" it is written with 2 plus signs. like "17: Nc7++"

Offline

#27 2008-03-29 04:38:26

LuisRodg
Real Member
Registered: 2007-10-23
Posts: 322

Re: Chess

Also. I was just playing this game:

1: f4  Nf6
2: Nc3  Nc6
3: e4  Nd4
4: Nf3  Nxf3+
5: Qxf3  c5
6: Bc4  d6

and I was trying to castle for the 7th move and it didnt let me. I think its because when the knight ate on f3 it was checking me. But since I ate with the queen and my king never moved I could still castle under chess rules. Might want to check on that.

Offline

#28 2008-03-29 05:44:09

JaneFairfax
Member
Registered: 2007-02-23
Posts: 6,868

Re: Chess

Er, I just made another en passant move – but only my pawn was moved and the computer’s pawn that was supposed to be captured was not captured. eek

Also Luis was perfectly entitled to castle from his position. The fact that his king was temporarily in check a few moves earlier doesn’t mean he can’t castle for the rest of the game. neutral

Offline

#29 2008-03-29 09:37:46

MathsIsFun
Administrator
Registered: 2005-01-21
Posts: 7,713

Re: Chess

The moves help me, as I can actually play the game and see what the computer does.

Luis: for some reason it thinks the King had been moved ... I will investigate.


"The physicists defer only to mathematicians, and the mathematicians defer only to God ..."  - Leon M. Lederman

Offline

#30 2008-03-29 10:22:53

JaneFairfax
Member
Registered: 2007-02-23
Posts: 6,868

Re: Chess

The king had not been moved in Luis’s game. My suspicion is that the king was in check earlier – and the program thought Luis couldn’t castle any more. This is not correct. While you can’t castle when your king is in check, you can when the check is removed (provided you haven’t moved your king or the rook towards which you are castling). neutral

Offline

#31 2008-03-29 10:24:22

Zach
Member
Registered: 2005-03-23
Posts: 2,075

Re: Chess

JaneFairfax wrote:

I also just found out that the computer doesn’t understand the rule of en passant. yikes

It understands the rules, it allows you to do it.

It just doesn't allow you to do it IN FULL and take the piece. Also, I'd like to choose what my prawn becomes.


Boy let me tell you what:
I bet you didn't know it, but I'm a fiddle player too.
And if you'd care to take a dare, I'll make a bet with you.

Offline

#32 2008-03-29 11:49:46

MathsIsFun
Administrator
Registered: 2005-01-21
Posts: 7,713

Re: Chess

It was the routine that looks for Checkmate. It tests all possible moves to remove Check, and did not correctly reset the status after doing this.

I will now check the en-passant thing. If anyone can post the moves that lead to the fail, that will help.


"The physicists defer only to mathematicians, and the mathematicians defer only to God ..."  - Leon M. Lederman

Offline

#33 2008-03-29 12:06:24

MathsIsFun
Administrator
Registered: 2005-01-21
Posts: 7,713

Re: Chess

Posted a new version (v0.74) which hopefully fixes both the castling and en-passant naughties.

I hope to come up with a *slightly* more difficult version, but I am already hitting time limits.


"The physicists defer only to mathematicians, and the mathematicians defer only to God ..."  - Leon M. Lederman

Offline

#34 2008-03-30 04:50:26

JaneFairfax
Member
Registered: 2007-02-23
Posts: 6,868

Re: Chess

The computer’s current level is just fine for beginners. It has already beaten me twice (and I consider myself high-intermediate). tongue

Offline

#35 2008-03-30 08:13:44

MathsIsFun
Administrator
Registered: 2005-01-21
Posts: 7,713

Re: Chess

OK, then! smile


"The physicists defer only to mathematicians, and the mathematicians defer only to God ..."  - Leon M. Lederman

Offline

#36 2008-03-30 10:28:13

mathsyperson
Moderator
Registered: 2005-06-22
Posts: 4,900

Re: Chess

I managed to beat it in around 10 moves just now. I don't have the game notation because halfway through I clicked the "Test" button to see what it did and lots of weird stuff overwrote it.
It also flashed up the "Well Done" message as if I'd won.

It was a slight variation of the one where you put your queen diagonally next to the enemy king and a bishop stopping the king from taking her. A knight helped out too. The computer won't fall for that anymore though. smile


Why did the vector cross the road?
It wanted to be normal.

Offline

#37 2008-03-30 12:58:43

JaneFairfax
Member
Registered: 2007-02-23
Posts: 6,868

Re: Chess

mathsyperson wrote:

I managed to beat it in around 10 moves just now. I don't have the game notation because halfway through I clicked the "Test" button to see what it did and lots of weird stuff overwrote it.
It also flashed up the "Well Done" message as if I'd won.

It was a slight variation of the one where you put your queen diagonally next to the enemy king and a bishop stopping the king from taking her. A knight helped out too. The computer won't fall for that anymore though. smile

This is the classic game known as Fool’s Mate. I managed to beat the computer with it in only six moves:

1: e3  Nc6
2: Bc4  Nf6
3: Qf3  d6
4: d4  Nxd4
5: exd4  Nd7
6: Qxf7

Really, Fool’s Mate is so stupid I hardly thought any self-respecting chess-playing software would even try to be beaten by it. tongue

Offline

#38 2008-03-30 13:11:46

JaneFairfax
Member
Registered: 2007-02-23
Posts: 6,868

Re: Chess

Wait. Mate in just four moves!

1: e4  Nf6
2: Qf3  Ng8
3: Bc4  Nc6
4: Qxf7

I hope the “slightly” more difficult version is going to take care of that. big_smile

Offline

#39 2008-03-30 13:26:21

MathsIsFun
Administrator
Registered: 2005-01-21
Posts: 7,713

Re: Chess

Ouch smile

But I always get:

1: e4  Nf6
2: Qf3  Nxe4

Still ends in mate, though. sad

(BTW: there is a mild "ranomity" in the chess game, to keep it interesting ... you may have noticed it sometimes makes different moves)

Yes, hopefully I can get it past that.


"The physicists defer only to mathematicians, and the mathematicians defer only to God ..."  - Leon M. Lederman

Offline

#40 2008-03-31 02:47:49

AshJones555
Member
Registered: 2006-05-15
Posts: 19

Re: Chess

1: Nf3  Nf6
2: Ng5  Nc6
3: e3  d6
4: Bc4  Bf5
5: Nxf7  Bd3
6: Nxd8  e5
7: Nxc6  Be7
8: Nxe7  Bxc4
9: Nf5  O-O-O
10: b3  Bd3
11: cxd3  Rf8
12: Ne7  Kb8
13: Bb2  e4
14: Bxf6  Rxf6
15: Nd5  Rxf2
16: Kxf2  exd3
17: Qf3  Rf8
18: Nf4  d5
19: Nc3  d4
20: exd4  g5
21: Ne6  h5
22: Nxf8  g4
23: Qf5  h4
24: Ng6  c6
25: Re1  g3
26: hxg3  hxg3
27: Kxg3  Kc7
28: Re7  Kd6
29: Qc5

I'm a bit of a begginer but i managed to win, the computer seems to use a variety of decent moves and seemingly pointless moves and I agree that a + for check should be included in the coding because it's interesting to see how check could develop into forced mate etc.

Last edited by AshJones555 (2008-03-31 02:48:32)

Offline

#41 2008-03-31 05:33:09

AshJones555
Member
Registered: 2006-05-15
Posts: 19

Re: Chess

oh and:
1: e4  Nf6
2: Bc4  Nxe4
3: Qh5  Nc6
4: Qxf7
tongue
basically the same as Jane.

Offline

#42 2008-03-31 12:33:03

MathsIsFun
Administrator
Registered: 2005-01-21
Posts: 7,713

Re: Chess

Posted version 0.76 (Chess) that now has difficulty levels. Refresh the page if you don't see "v0.76".

Can you still beat it easily at "Medium"?

I also have some code that will choose different moves (of the best available) to provide an interesting game, but it is switched off so that we can more easily duplicate errors if we need to.


"The physicists defer only to mathematicians, and the mathematicians defer only to God ..."  - Leon M. Lederman

Offline

#43 2008-03-31 21:08:35

MathsIsFun
Administrator
Registered: 2005-01-21
Posts: 7,713

Re: Chess

Note: the "medium" level has the addition of an "attacked/protected" count. So if a piece is attacked but not protected a penalty of 30% of the pieces value is added.

To work out "attacked and protected" I look at each piece in turn and record on the board where it can move. This gives me a count for each square. Then I look at each piece's location to see if the enemy has more pieces that can move onto its square than friendly pieces can.

But this does not account for relative values of the pieces. For example if a pawn attacks the Queen.

Can anyone think of it quick and effective way of accounting for relative values of pieces?


"The physicists defer only to mathematicians, and the mathematicians defer only to God ..."  - Leon M. Lederman

Offline

#44 2008-04-01 01:00:03

mathsyperson
Moderator
Registered: 2005-06-22
Posts: 4,900

Re: Chess

There's a fairly well-known system that gives labels each piece as being worth an amount of pawns:

Knight - 3 pawns
Bishop - 3 pawns
Rook - 5 pawns
Queen - 9 pawns

Of course, the actual value of pieces is very situational. Knights are worth far more than bishops in the early game, bishops are better than knights in endgame, and it's perfectly possible to have a pawn being more valuable than a queen in certain positions.
But this system is still much better than treating all pieces equally.


Why did the vector cross the road?
It wanted to be normal.

Offline

#45 2008-04-01 02:22:34

LuisRodg
Real Member
Registered: 2007-10-23
Posts: 322

Re: Chess

Look at this game playing medium style:

1: e4  Nf6
2: Nc3  Nc6
3: f4  d6
4: Nf3  Bd7
5: Bb5  Nxe4
6: Nxe4  d5
7: Nc5  b6
8: Nxd7  a6
9: Bxc6  Rc8
10: Nf6

Why did it give me a free piece at move 5 with Nxe4?

Also when I checkmated it with a double check it didnt record the final move as Nf6++ or even Nf6+ indicating im checking him with knight and bishop.

Offline

#46 2008-04-01 02:47:26

LuisRodg
Real Member
Registered: 2007-10-23
Posts: 322

Re: Chess

By the way, this topic made me make my own chess engine in C++. Its even weaker than this one though. The move generating and implementing the alpha-beta searching took quite a while for me so my evaluation function is as simple as you can get. Its basically what mathyperson suggested of the values of the pieces.

int Eval_function()
{
    int value_piece[6] = {VALUE_PAWN, VALUE_KNIGHT, VALUE_BISHOP, VALUE_ROOK, VALUE_QUEEN, VALUE_KING};
    int score = 0;
    for (int i=0;i<64;i++) {
        if (color[i] == WHITE)
            score += value_piece[piece[i]];
        else if (color[i] == BLACK)
            score -= value_piece[piece[i]];
    }
    if (side == WHITE)
        return score;
    return -score;
}

This is as simple as you can get. If you want it to improve a little then you need to start implementing other deductions and bonus in scores. For example, as you can see in this code, the score consists ONLY of the pieces in the board. It doesnt take into account any positional knowledge etc.

A suggestion for you MathIsFun, which is something im going to implement in mine in the summer (since im almost in finals right now and getting to where i am basically took me all day yesterday and I had to study for Discrete sad ) Start tweaking your evaluation function such as this:

give bonus score if a side has a rook on an open file.
give bonus score if 3 pawns are covering the king.
give bonus score if theres a knight near the king.
deduct score if the king has an open file.
give bonus score if the bishop's diagonal are longer = more mobility.
give bonus score if your pawns control the center of the board.

Etc. I read this a site once about how to tweak your evaluation fucntion. It looks very simple but it actually serves of help in the strength of play.

Also, MathIsFun you asked about relative value of the pieces. I assume you have your knights valued as 3 (or 300, as I do so all my work is in integer). In a simple evaluation function where you only take into account the value of the piece, your basically saying that a Knight in its original position is worth the same as a knight placed on a key spot such as e4 and d4 controlling the center of the board. Same can be said about having control of the center. If any of you took chess classes when you were little, I can still remember my trainer "control the center of the board..." etc. Having control of the center is a key element.  So as I said, a knight placed and protected in d4 is worth more than 3 but also a backwards knight in b1 which offers no help is worth less than 3. Its all relative to the position. Every piece has similar stuff, if you add this to every piece etc. The engine will increase its playing strength dramatically even if it sounds that your doing simple stuff.

Hope I helped.

Offline

#47 2008-04-01 04:05:35

LuisRodg
Real Member
Registered: 2007-10-23
Posts: 322

Re: Chess

Meh.

I was just playing with my stupid engine and the game went on like this:

e4 d6
f4 Na6
Nf3 Rb8
Bxa6 Ra8

Even if my evaluation function is as simple as you can get, when its searching, guiding itself by my eval function, why did it find Ra8 to be "better" than bxa6? If I understand this alpha-beta searching, the search function is supposed to evaluate every single position, bxa6 is supposed to give a higher score than Ra8 since with any other move that isnt bxa6 the score goes down by 3...

Hmm.

Offline

#48 2008-04-01 08:21:46

MathsIsFun
Administrator
Registered: 2005-01-21
Posts: 7,713

Re: Chess

Alpha-Beta stops searching down a branch when it finds it is getting a worse result than a previous branch. It is searching for the "best worst", so a "worse worse" does not need to be checked further. (Example: if moving the queen results in losing a pawn, and then you start testing a Knight's move and find you have lost a Bishop you don't need to see if there are any worse possibilities for that Knight's move)

I already have material values (100 for pawn, 900 for queen etc) and lots of positional code. I am looking for an intelligent "piece exchange" function. But it all has to be super-rapid (it is a "how smart can I be in a limited time" thing).


"The physicists defer only to mathematicians, and the mathematicians defer only to God ..."  - Leon M. Lederman

Offline

Board footer

Powered by FluxBB