Mobility
Moderators: hgm, Rebel, chrisw
-
- Posts: 226
- Joined: Sun Mar 08, 2009 3:08 pm
- Location: Canada
Re: Mobility
Sorry, the code above won't work. I would have removed it but it was too late.
outAtime
-
- Posts: 226
- Joined: Sun Mar 08, 2009 3:08 pm
- Location: Canada
Re: Mobility
Trying this...
where..
seems to work.. testing. Thanks.
Code: Select all
int wknight_mobility(int squaren)
{
int n;
int g = 0;
for (n = 0; n < 8; n++)
//n_sq = squaren + n_offsets[n];
if (board[squaren + n_offsets[n]] == npiece || board[squaren + n_offsets[n]] == (black_piece)) // or == opponent
g++;
return g;
}
int bknight_mobility(int squaren)
{
int n;
int g = 0;
for (n = 0; n < 8; n++)
//n_sq = squaren + n_offsets[n];
if (board[squaren + n_offsets[n]] == npiece || board[squaren + n_offsets[n]] == (white_piece)) // or == opponent
g++;
return g;
}
Code: Select all
#define black_piece bpawn | bknight | bbishop | brook | bqueen | bking
#define white_piece wpawn | wknight | wbishop | wrook | wqueen | wking
outAtime
-
- Posts: 318
- Joined: Thu Mar 09, 2006 1:07 am
Re: Mobility
This won't work!outAtime wrote:Trying this...
where..Code: Select all
int wknight_mobility(int squaren) { int n; int g = 0; for (n = 0; n < 8; n++) //n_sq = squaren + n_offsets[n]; if (board[squaren + n_offsets[n]] == npiece || board[squaren + n_offsets[n]] == (black_piece)) // or == opponent g++; return g; } int bknight_mobility(int squaren) { int n; int g = 0; for (n = 0; n < 8; n++) //n_sq = squaren + n_offsets[n]; if (board[squaren + n_offsets[n]] == npiece || board[squaren + n_offsets[n]] == (white_piece)) // or == opponent g++; return g; }
seems to work.. testing. Thanks.Code: Select all
#define black_piece bpawn | bknight | bbishop | brook | bqueen | bking #define white_piece wpawn | wknight | wbishop | wrook | wqueen | wking
Please read my last posting again. Carefully!
And understand it first before you change your source.
You need to understand the difference between
-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6
and the powers of 2 that have only one bit set in their binary representation:
2048, 1024, 512, 256, 128, 64, 0, 1, 2, 4, 8, 16, 32
Google for binary numbers.
You need to understand the difference between the | operator and the || operator.
You need to understand why the condition in the first case is
if ( board[sq] > 0 ) or if ( board[sq] < 0 ) // omitting the border test
and the condition in the latter case is
if ( board[sq] & opp_pieces )
where opp_pieces is a | combination of power_of_2 piece bits.
And may I suggest that you please notice the usage of the & operator
in the latter case.
Do not mix both models!
Most people prefer the simple number model.
That is -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6
Harald
-
- Posts: 2684
- Joined: Sat Jun 14, 2008 9:17 pm
Re: Mobility
Please just one thing and I won't bother you anymore. If you want your positive attitude at learning a computer language do survives more then one month then I humbly suggest the following:outAtime wrote: seems to work.. testing. Thanks.
1) Understand the difference between debugging and testing. It seems is absolutely blurred for you, actually this two activities are _completely_ different and aimed at completely different purposes.
2) Learn the basic of debugging, printf, setting a given position, monitoring the input and the output values out of a function. A book (in case an on-line one) could be extremely beneficial for you.
3) Run the code (what you call "to test") only when it is absolutely clear for you what the code does, don't run a black box you don't understand: you learn nothing and just waste your time.
4) Trying to do by yourself is a good thing, but at this so early stage of programming language knowledge I have to suggest to look (and try to understand) other's people code: it is fine trying to write a novel by yourself, but first you should learn the grammar.
Have fun and good luck !
-
- Posts: 226
- Joined: Sun Mar 08, 2009 3:08 pm
- Location: Canada
Re: Mobility
Code: Select all
void init_game(void) {
/* set up a new game: */
int i;
int init_board[144] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 7, 3, 11, 9, 5, 11, 3, 7, 0, 0,
0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0,
0, 0, 13, 13, 13, 13, 13, 13, 13, 13, 0, 0,
0, 0, 13, 13, 13, 13, 13, 13, 13, 13, 0, 0,
0, 0, 13, 13, 13, 13, 13, 13, 13, 13, 0, 0,
0, 0, 13, 13, 13, 13, 13, 13, 13, 13, 0, 0,
0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0,
0, 0, 8, 4, 12, 10, 6, 12, 4, 8, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
memcpy(board, init_board, sizeof(init_board));
for (i = 0; i <= 143; i++)
moved[i] = 0;
if (board[sq] < 0)" and I was a bit lost because I never thought to define them as negative #'s for opposite color.... Thanks. [/code]
outAtime
-
- Posts: 226
- Joined: Sun Mar 08, 2009 3:08 pm
- Location: Canada
Re: Mobility
I've tried using negative #'s for the black pieces, and also the power of 2 numbers to define the pieces but neither seems to be working, a number like 2048 is just too big it seems and gets changed at compile to an unregistered int. I also tried using 7 as npiece and larger numbers for black pieces (>7), smaller for white (<7) and the program was returning illegal moves. I've looked at alot of code (fruit, sloppy, daydreamer, pawny, gull, etc..) and just cant find any solutions. Oh, well... Are there any good programs that _don't_ count attacked enemy pieces as a mobility bonus? I was also thinking of maybe trying something simple like...
the idea being even though if there is a wking and a wpawn being attacked by.. say a black knight, the bonus will be attributed to attacking the king, no bonus for attacking the pawn... but maybe its more valuable to attack the king and the rest worked out by search...
maybe it would be better to have wbishop before wrook in case of a knight to try and get that bonus first...
BTW.. I really do appreciate the help I have received here on this topic (and others) and I hope it has also proved of some use to people with similar questions. Thanks.
Code: Select all
#define b_opponent wking || wqueen || wrook || wbishop || wknight || wpawn
maybe it would be better to have wbishop before wrook in case of a knight to try and get that bonus first...
BTW.. I really do appreciate the help I have received here on this topic (and others) and I hope it has also proved of some use to people with similar questions. Thanks.
outAtime
-
- Posts: 900
- Joined: Tue Apr 27, 2010 3:48 pm
Re: Mobility
Whatever you do, always put parentheses around macro contents:
Otherwise you're setting yourself up for weird and hard to find bugs due to operator priorities messing up the usage of your macro.
Code: Select all
#define b_opponent (wking || wqueen || wrook || wbishop || wknight || wpawn)