Creating the game Hex 7 in Mathematica

Daniela Fuschetto (Onceuponamemory4@aim.com
Math 213 -- Mathematics with Mathematica, Fall 2009 
December 3, 2009

Abstract

My project investigates the question.  I use certain Mathematica commands which are put together in innovative ways.  I learn certain things from my project.

Section 1. Introduction

1.1 Background

When I started this project I decided to choose a game that was not only fun to play but gave me a challenge while playing it. I found this game while looking at the different impartial game; you can play this game at the following link:  http://www.cut-the-knot.org/Curriculum/Games/Hex7.shtml. The reason why I choose this game was I wanted a challenge in creating a game that from what I saw has not been created on mathematica yet. I knew before even starting this project that this will be a challenge for me and it was one I was willing to put the time and effort in to try my best and figure out how to create a game like Hex on mathematica. Even if I am not able to complete this in the time I have it’s defiantly a project that I can see myself continuing in the future to complete.

1.2 Problem Statement

The problem statement I answer is:

How to create the game Hex 7 on mathematica.

1.3 Useful Commands

There are many different commands that I tried to use while creating this game.Some of which failed and I couldn’ t go any farther with which made me change my idea several times.Some that I tried to use came from different creations I found on mathematica.Some of the ones that have failed I will discuss later on in this project towards then end.The different commands that I used to create this game were : GraphicsGrid, Rotate, & Graphics, I explain each of then right below.

The first one I am going to explain is GRAPHICS which is also used when creating a GraphicsGrid.
You can start off with a simple Graphics[Disk[]] or Graphic[Square[]] or Graphic[Circle[]] in my project I used Graphics[Disk[]]. There are ways in which you can create different colored graphics and different sizes. In order to play the game you have to know how to change the colors of the different disk and that is done by just simply adding {} around the "Disk[]" and writing which color you need to use so for example, say I wanted a purple disk I would put in Graphics[{Purple, Disk[]}] and you just got to make sure that the color you use first letter in capital.

Graphics[Disk[]]

Graphics[{Purple,Disk[]}]

The second comand i am going to explain is the GRAPHICSGRID. The set of for GraphicGrid is GraphicsGrid[{{Graphics["shape"],Graphics["shape"],...}}] <<< That will give you just a row of how ever many circles, squares, or disk you will like and to make the next row you woulkd have to add a ","and then just repeat {....}. Examples below:
	First just a row of disk
	Second a 4x4 of disk

GraphicsGrid[{
{Graphics[Disk[]],
Graphics[Disk[]],
Graphics[Disk[]],
Graphics[Disk[]]}
}]

GraphicsGrid[{
{Graphics[Disk[]],
Graphics[Disk[]],
Graphics[Disk[]],
Graphics[Disk[]]},

{Graphics[Disk[]],
Graphics[Disk[]],
Graphics[Disk[]],
Graphics[Disk[]]},

{Graphics[Disk[]],
Graphics[Disk[]],
Graphics[Disk[]],
Graphics[Disk[]]},

{Graphics[Disk[]],
Graphics[Disk[]],
Graphics[Disk[]],
Graphics[Disk[]]}
}]

The third command I used was ROTATE, which i used to give the effect like the hex board does how its on a angle its a very simple command to use is just Rotate[f, θ].  When putting in the degree you can eaither put in the "°" or just simply writed in Degree, it will give the same output. I will show you all three commands together right below.

Rotate[GraphicsGrid[{
{Graphics[Disk[]],
Graphics[Disk[]],
Graphics[Disk[]],
Graphics[Disk[]]}
}],20°]
Rotate[GraphicsGrid[{
{Graphics[Disk[]],
Graphics[Disk[]],
Graphics[Disk[]],
Graphics[Disk[]]}
}],20Degree]

?Rotate

1.4 File Structure

In Section 2, I explain the code that I used to investigate my problem and in Section 3, I discuss my findings and mention topics for future work.

Section 2. Main Work

2.1 Investigating Buttons

My first thought was to create a grid of buttons that would be able to change two different colors, one for each player. but this didn't work out a well as i thought it would for the fact that there was to much dealing with the buttons to create such an effect. I had help from one program in mathematica to get me somewhere but not far enough, the program is called, Simple Phone Dialer, and can be found here: http://demonstrations.wolfram.com/SimplePhoneDialer/ . This help by showing me that it was possiable to create a grid of buttons which was one thing i was getting stuck on. But this idea fell short when I was trying to find a way to change the program to work in my advantage and i was unable to get a grid that was 7x7 and buttons that would be able to change two different colors. I was also unable to use this way for i was unsure what some of the commands are that were in this program so i would of been unable to explain to the fullest how I was able to do this. Below I will show you how far I came with this idea but will not be able to explain to the fullest.

Grid[
Partition[
MapIndexed[DynamicModule[{b=Black},Button["",Dynamic[b=Blue],Background->Dynamic[b],ImageSize->{50,50}]]&,
Flatten[Outer[List,{697,770,852,941},{1209,1336,1477}],7]],7]]

The commands that I can somewhat explain to you are the Grid and the Button.

	The Grid command is simple it is easy to explain when creating a grid of a table which is not the way it is used above but is a way that it could be used. Grid[Table[" ",{#},{#}]]
	
	The Button command can range from a simple command to a difficult command. The format is Button[label, action]. Below will be some examples from the ?Button area. The last example is what I played around with to make the buttons above change from black to blue.

Grid[Table[\[Placeholder],{4},{4}]]

Button["Click Here", Print[20!]]

DynamicModule[{b=Automatic},Button["",Dynamic[b=Apply[RGBColor,RandomReal[{0,1},3]]],Background->Dynamic[b],ImageSize->{50,50}]]

As you can see from the above information I was unable to fully understand everything which is why I was able to change the programing to work in my advantange so I to a few steps back and dessided to go on a simpelr route in creating this game and even thought the final project is a hard game to play whith the codes I use i was still able to find a way to create the game.

2.2 The Grid for the Game

The following codes create the blank board for the game Hex.

Rotate[GraphicsGrid[{
(*Row 1*)
{Graphics[{Disk[]}],
(*Column 2*)
Graphics[{Disk[]}],
(*Column 3*)
Graphics[{Disk[]}],
(*Column 4*)
Graphics[{Disk[]}],
(*Column 5*)
Graphics[{Disk[]}],
(*Column 6*)
Graphics[{Disk[]}],
(*Column 7*)
Graphics[{Disk[]}]},
(*Row 2*)
{Graphics[{Disk[]}],
(*Column 2*)
Graphics[{Disk[]}],
(*Column 3*)
Graphics[{Disk[]}],
(*Column 4*)
Graphics[{Disk[]}],
(*Column 5*)
Graphics[{Disk[]}],
(*Column 6*)
Graphics[{Disk[]}],
(*Column 7*)
Graphics[{Disk[]}]},
(*Row 3*)
{Graphics[{Disk[]}],
(*Column 2*)
Graphics[{Disk[]}],
(*Column 3*)
Graphics[{Disk[]}],
(*Column 4*)
Graphics[{Disk[]}],
(*Column 5*)
Graphics[{Disk[]}],
(*Column 6*)
Graphics[{Disk[]}],
(*Column 7*)
Graphics[{Disk[]}]},
(*Row 4 *)
{Graphics[{Disk[]}],
(*Column 2*)
Graphics[{Disk[]}],
(*Column 3*)
Graphics[{Disk[]}],
(*Column 4*)
Graphics[{Disk[]}],
(*Column 5*)
Graphics[{Disk[]}],
(*Column 6*)
Graphics[{Disk[]}],
(*Column 7*)
Graphics[{Disk[]}]},
(*Row 5*)
{Graphics[{Disk[]}],
(*Column 2*)
Graphics[{Disk[]}],
(*Column 3*)
Graphics[{Disk[]}],
(*Column 4*)
Graphics[{Disk[]}],
(*Column 5*)
Graphics[{Disk[]}],
(*Column 6*)
Graphics[{Disk[]}],
(*Column 7*)
Graphics[{Disk[]}]},
(*Row 6*)
{Graphics[{Disk[]}],
(*Column 2*)
Graphics[{Disk[]}],
(*Column 3*)
Graphics[{Disk[]}],
(*Column 4*)
Graphics[{Disk[]}],
(*Column 5*)
Graphics[{Disk[]}],
(*Column 6*)
Graphics[{Disk[]}],
(*Column 7*)
Graphics[{Disk[]}]},
(*Row 7*)
{Graphics[{Disk[]}],
(*Column 2*)
Graphics[{Disk[]}],
(*Column 3*)
Graphics[{Disk[]}],
(*Column 4*)
Graphics[{Disk[]}],
(*Column 5*)
Graphics[{Disk[]}],
(*Column 6*)
Graphics[{Disk[]}],
(*Column 7*)
Graphics[{Disk[]}]}
},Spacings->0],25°]

2.3 How to change the colors in the grid

There are many different colors to use but I limited for the two players to pick from the following colors:

GraphicsGrid[{{Graphics[{Red,Disk[]}],
Graphics[{Orange,Disk[]}],
Graphics[{Yellow,Disk[]}],
Graphics[{Green,Disk[]}],
Graphics[{Blue,Disk[]}],
Graphics[{Purple,Disk[]}]}}]

Above I also showed how to make each color and the way you have to put it in, in order to change the disk from black to the color of your choice. To play the game each player will start of by pick one of the above colors, you can either copy and paste every time you move or just add in the color and a “,” after the color(I have already added the {}, so you don’t have to add them). So if you are just adding in the color you would have to add in what is in caps, you have Graphics[{Disk[]}] all you have to add is Graphics[{PURPLE, Disk[]}].

	The difficult part of playing this game is being able to find the codes that correspond to the disk you what to choose. To make it somewhat easier I have labeled each row and for each row I listed which of the columns each of the graphics are in each row.

Section 3. Conclusion and Future Work

3.1 Summary

Although the way I created this game is a difficult way to play it, nun the less it does answer what I was trying to create in the beginning. Which was to create a two player game that was similar to the game Hex.

3.2 Discussion

When I first started out I aim for something higher than what I came out with in the end. But while doing this project I was able to learn more about different commands I didn’t know how to use, and I also the help center definitely helped me out a lot though this project. I was definitely challenged throughout this whole project and when I started I definitely didn’t think that this would be easy. I was challenge to find a new way after trying to figure one thing out for so long, to realize that although your first thought is a good one and in the long run will work very well. But, for the amount of time I had I was unable to learn all the commands I needed in time to finish this project, to the standard I hoped for. But, nun the less this project is one that I have learned a lot about and one I am not willing to give up on.

3.3 Future Work

If I had more time to work on this project I would have definitely love to lean more about buttons and the commands I would need in order to change it to just two colors. To make not just a plan gird, but a grid of buttons that would be able to change colors. I would also like to investigate different techniques’ used by others in there projects to do the similar things that I was hoping to accomplish. I would hope to truly create this game in a way were it would be not only easier to play but a game that would be quicker to play. That wouldn’t take so much time figuring out which code you need to change to change the disk color.

Section 4. References

The Link for the Hex 7 Game:
	 http://www.cut-the-knot.org/Curriculum/Games/Hex7.shtml
	 
The link for the Simple Phone Dialer:
	 http://demonstrations.wolfram.com/SimplePhoneDialer/ 
	 
The other things i mostly used where the help:
	?GraphicsGrid
	?Rotate
	?Graphics
	?Button
	?Grid
	etc.