int detect_win_including_position(int color, int x, int y) { if(span_in_direction(color, x, y, 1, 0)+span_in_direction(color, x, y, -1, 0) >= 5) return 1; if(span_in_direction(color, x, y, 1, 1)+span_in_direction(color, x, y, -1, -1) >= 5) return 1; if(span_in_direction(color, x, y, 0, 1)+span_in_direction(color, x, y, 0, -1) >= 5) return 1; if(span_in_direction(color, x, y, -1, 1)+span_in_direction(color, x, y, 1, -1) >= 5) return 1; return 0; } int span_in_direction(int color, int x, int y, int dx, int dy) { int length; length = 0; while(x >= 0 && y >= 0 && x < 15 && y < 15 && board[COORD(x,y)]==color) { length++; x+=dx; y+=dy; } return length; }
but there is a bug in that.. fixed now.
A slightly annoying thing is that when you start there are no counters so the buttons are all small, then you click and all the buttons grow in size. I can't be bothered to fix it (I suppose I should add transparent images to the buttons to fix it).
I have been thinking a bit about evaluation functions and tabulation/memoization (in gomoku only board position matters, not the order of moves - so redundancy when searching the tree could blow up the search times) but it's probably too early to be thinking about these things.
I thought a good warmup would be start with minimax to write a knots-and-crosses AI, then write a connect-4 AI using simple alpha-beta then start to tackle gomoku directly. It's really boring to write the knots-and-crosses but it's a good idea to build up step by step.
No comments:
Post a Comment