flat assembler
Message board for the users of flat assembler.

Index > Tutorials and Examples > better opengl example (hex game+ai)

Author
Thread Post new topic Reply to topic
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 09 Nov 2013, 06:56
The object of the game of hex is to connect your sides of a rhombus. As I got too carried away with the graphics on my geometry wars-like game, I decided to post this example that clearly and simply illustrates:

- using opengl shaders for all lighting effects
- fully functional camera, move with tyfghn, and rotate with uiojkl
- fully functional hex game suitable from human and computer play
- Monte Carlo method for weak computer play; no knowledge is implemented
- red-black trees for transposition table in computer ai
- how to detect when either player has connected their sides using simd instructions

to play a white/black stone, click the left/right mouse button
to remove a stone, click it
side with a win will flash


Last edited by tthsqe on 06 Feb 2014, 22:01; edited 11 times in total
Post 09 Nov 2013, 06:56
View user's profile Send private message Reply with quote
MHajduk



Joined: 30 Mar 2006
Posts: 6115
Location: Poland
MHajduk 10 Nov 2013, 20:52
One thing that could make this game more interesting would be an option to play against the computer. Now, as I understood, it is a version for two human players.

Another thing that could be improved is automatic update of the view when the application window is changing its size - when you drag the window border in one direction (inwards) and after that you immediately start to drag it in the opposite direction (outwards) keeping the left mouse button pressed all the time you may see such an image:

Image
Post 10 Nov 2013, 20:52
View user's profile Send private message Visit poster's website Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 10 Nov 2013, 21:18
OK, the window size thing is easy to change, but writing some (decent) ai is not a piece of cake. Hex is also hard. If we are to keep things simple, I could try a Monte Carlo tree search, but I bet it will produce close to random play in the beginning.
Post 10 Nov 2013, 21:18
View user's profile Send private message Reply with quote
MHajduk



Joined: 30 Mar 2006
Posts: 6115
Location: Poland
MHajduk 10 Nov 2013, 21:27
I agree that the game tree may be huge in size like a chess game tree. It may grow expotentially as the number of fields grows. BTW, is the hex game board somehow strictly "normalized" in size?
Post 10 Nov 2013, 21:27
View user's profile Send private message Visit poster's website Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 12 Nov 2013, 03:40
What do you mean by 'normalized in size'?
I can say that if the board is NxN in size then each row needs 2(N+1) bits, so 15 is the largest size if each row is to fit in a dword.
Post 12 Nov 2013, 03:40
View user's profile Send private message Reply with quote
MHajduk



Joined: 30 Mar 2006
Posts: 6115
Location: Poland
MHajduk 12 Nov 2013, 17:38
I meant whether the hex game has a constant number of fields on the board (like chess for example) or it's just a question of an arbitrary choice of the game creator. Smile

I read in Wikipedia that the hex game can be played on boards with various numbers of fields, so the game isn't "normalized" in the aforementioned meaning. Wink
Post 12 Nov 2013, 17:38
View user's profile Send private message Visit poster's website Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 17 Nov 2013, 10:33
oh, I finally get what you mean by 'fields'. You can play it on a board of any size MxN. 15x15 should be interesting for both computers and humans. If the starting position is empty,
if M != N, shorter color has a winning stategy
if M = N or the position is symmetric, first color has a winning strategy
Post 17 Nov 2013, 10:33
View user's profile Send private message Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 20 Nov 2013, 07:40
I got some ai working in the hex game now. The two levels are '(1)random' and '(2)monte carlo'. Level 2 does sometimes produce good moves and can consistently beat Level 1.
Post 20 Nov 2013, 07:40
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.