Daily Archives: 4/8/2007

Debugging…

I didn’t have much time to work on my checkers program this weekend. Still, in the back of my head, I was troubled by something: the random game player that I wrote revealed that red was winning somewhere around 55% of the total games. That disturbed me a little: I didn’t expect the assymetry of having the first move would create that strong an effect. I also had done some profiling using gprof, and had discovered that the white capture routines were using significantly less time than the red. I thought this was curious too. Finally, a moment of clarity dawned on me, and I set the program up to force white to move first, and the bias toward red victories continued. Well, that meant that there was something assymetric in the routines that generated moves for each side. The vast majority of this code is written by a Python script, and it seemed unlikely that it would be screwed up. A small amount was generated by hand with some assistance from a script to generate some bitmasks.

The offending routine was the one which tried to find the location of all white checker jumps:

BitBoard
WhiteJumpers(CheckerBoard *b)
{   
    BitBoard U = ~(b->R|b->W) ;
    BitBoard M ;
    
    M  = (b->W & JREV_37) & (b->R < < 3) & (U << 7) ;
    M |= (b->W & JREV_47) & (b->R < < 4) & (U << 7) ;
    M |= (b->W & JREV_49) & (b->R < < 4) & (U << 9) ;
    M |= (b->W & JREV_59) & (b->R < < 5) & (U << 9) ;

    BitBoard WK = b->R & b->K ;
    if (WK) {
        M |= (WK & JFWD_37) & (b->R >> 3) & (U >> 7) ;
        M |= (WK & JFWD_47) & (b->R >> 4) & (U >> 7) ;
        M |= (WK & JFWD_49) & (b->R >> 4) & (U >> 9) ;
        M |= (WK & JFWD_59) & (b->R >> 5) & (U >> 9) ;
    }

    return M ;
}

Can you spot the error? Yep, a copy paste error where I compute WK: it should be b->W and not b->R. Stupid me, but kudos to me for being able to localize it based upon my gut instinct.

[tags]Checkers,Programs[/tags]

Was Hank Aaron really that good?

My son innocently asked “was Hank Aaron really that good?” while they were flashing stats showing how various active players might have a shot at Aaron’s home run record. I said “yes, he really was”, and then ran a quick database query that produced the following career numbers:

Hank Aaron|116.863636363636
Stan Musial|104.556818181818
Willie Mays|103.397727272727
Ty Cobb|99.7840909090909
Babe Ruth|98.7443181818182
Barry Bonds|98.5909090909091
Pete Rose|98.0454545454546
Carl Yastrzemski|94.4147727272727
Eddie Murray|91.9943181818182
Rafael Palmeiro|91.8409090909091
Frank Robinson|91.5852272727273
Dave Winfield|88.9943181818182
Cal Ripken|88.0909090909091
Tris Speaker|86.9488636363636
Lou Gehrig|86.25
George Brett|85.9772727272727
Mel Ott|85.9261363636364
Jimmie Foxx|84.4772727272727
Ted Williams|83.25
Honus Wagner|82.875

The number associated with each name if the total bases by each player expressed in miles. Aaron had more than twelve miles more career total bases than the next in line. Bonds has no chance of beating that record.

[tags]Baseball, Fun with Databases[/tags]