Start adding bitwise opperators. Finish with Justin

master
Tait Hoyem 5 years ago
parent 792d0cc5ee
commit 3a6c0a0562

@ -0,0 +1,27 @@
#ifndef BITWISE_H
#define BITWISE_H
// Using macros for ease of use, can also use inline functons, but I don't see the point.
/*
* From (Position): 6 bits (2^6 == 64) possibilities
* To (Position): same as above
* Captured piece, if any: 4 bits (16) possibilities
* Promoted to, if any: 4 bits (16) possibilities
* en passant flag: 1 bit
* pawn starting move flag: 1 bit
* castle move flag: 1 bit
*
* 0000 0000 0000 0000 0011 1111 -> From square position (0x3F)
* 0000 0000 0000 1111 1100 0000 -> To square position (>> 6 0xFB)
* 0000 0000 1111 0000 0000 0000 -> captured piece, if any (>> 12 0xF)
* 0000 1111 0000 0000 0000 0000 -> if prmoted, what to? (>> 16 0xF)
* 0001 0000 0000 0000 0000 0000 -> en passant (0x100000)
* 0010 0000 0000 0000 0000 0000 -> pawn starting move (0x200000)
* 0100 0000 0000 0000 0000 0000 -> castle move (0x400000)
* */
#define FROMSQ(m) ((m) & 0x3f)
#define TOSQ(m) ((m>>6) & 0x3f)
#endif

@ -1,4 +1,5 @@
defualt: build
defualt: all.out
bitwise: bitwise.out
catch_main.o:
g++ -w -c -o catch_main.o catch_main.cpp
@ -6,5 +7,9 @@ catch_main.o:
custom_printing.o:
g++ -w -I../src/ -c -o custom_printing.o custom_printing.cpp
build: catch_main.o custom_printing.o
g++ -std=c++11 -ggdb -w -I../src/ -o tests.out ../src/functions.cpp catch_main.o custom_printing.o tests_main.cpp
bitwise.out: catch_main.o
g++ -I../src/ -o bitwise.out catch_main.o bitwise_tests.cpp
# TODO: Allw all.out to contain bitwise tests
all.out: catch_main.o custom_printing.o
g++ -std=c++11 -ggdb -w -I../src/ -o all.out ../src/functions.cpp catch_main.o custom_printing.o tests_main.cpp

@ -0,0 +1,42 @@
#include <constants.h>
#include <bitwise.h>
#include "catch.hpp"
/*
* From (Position): 6 bits (2^6 == 64) possibilities
* To (Position): same as above
* Captured piece, if any: 4 bits (16) possibilities
* Promoted to, if any: 4 bits (16) possibilities
* en passant flag: 1 bit
* pawn starting move flag: 1 bit
* castle move flag: 1 bit
*
* 0000 0000 0000 0000 0011 1111 -> From square position (0x3F)
* 0000 0000 0000 1111 1100 0000 -> To square position (>> 6 0xFB)
* 0000 0000 1111 0000 0000 0000 -> captured piece, if any (>> 12 0xF)
* 0000 1111 0000 0000 0000 0000 -> if prmoted, what to? (>> 16 0xF)
* 0001 0000 0000 0000 0000 0000 -> en passant (0x100000)
* 0010 0000 0000 0000 0000 0000 -> pawn starting move (0x200000)
* 0100 0000 0000 0000 0000 0000 -> castle move (0x400000)
* */
const unsigned int GET_FROM_PIECE_INT = 0x3f;
const unsigned int GET_FROM_PIECE_INT2 = 0x3e;
// Want:
// 1111 1111 1110
// FFE
const unsigned int GET_TO_FROM_PIECE_INT = 0xffe;
// Want:
// 1111 1011 1111
// FBF
const unsigned int GET_TO_FROM_PIECE_INT2 = 0xfbf;
TEST_CASE("Test that bitwise operators return appropriate values. Move.from", "[bitwise_from_pos]"){
CHECK(FROMSQ(GET_FROM_PIECE_INT) == Position::H1);
CHECK(FROMSQ(GET_FROM_PIECE_INT2) == Position::G1);
CHECK(TOSQ(GET_TO_FROM_PIECE_INT) == Position::H1);
CHECK(FROMSQ(GET_TO_FROM_PIECE_INT) == Position::G1);
CHECK(TOSQ(GET_TO_FROM_PIECE_INT2) == Position::G1);
CHECK(FROMSQ(GET_TO_FROM_PIECE_INT2) == Position::H1);
}
Loading…
Cancel
Save