Posted: Wed Jan 21, 2009 10:13 pm Post subject: Tic Tac Toe with 3D!
Tic Tac Toe with 3D 'X's and 'O's.
And probably still shorter than others at ~176 lines.
Turing:
View.Set("graphics:600,600,offscreenonly,nobuttonbar") type grid : record
value :int
used :boolean endrecord var g :array1.. 3, 1.. 3of grid
var turn :boolean:=true var font :int:=Font.New("Algerian:50") var results :array0.. 3ofstring:=init("", "'X' Wins", "'O' Wins", "Cats Game") type points : record
x, y, z :real
zA :real endrecord var px :array - 18.. 18, -18.. 18of points
var po :array - 18.. 18, -18.. 18of points
var xm, ym, bm :int var cm, sm :int var scale :int:=200
for x :1.. 3 for y :1.. 3
g (x, y).used :=false
g (x, y).value :=0 endfor endfor
proc LoadGraphO (var p :array - 18.. 18, -18.. 18of points) for x : -18.. 18 for y : -18.. 18
p (x, y).x :=cosd(x *10)*sind(y *10)
p (x, y).y :=sind(x *10)*sind(y *10)
p (x, y).z :=cosd(y *10) endfor endfor end LoadGraphO
proc LoadGraphX (var p :array - 18.. 18, -18.. 18of points) for x : -18.. 18by2 for y : -18.. 18
p (x, y).x := x / 20
p (x, y).y :=sind(y)
p (x, y).z := y / 20 endfor endfor for x : -17.. 18by2 for y : -18.. 18
p (x, y).x := x / 20
p (x, y).y := y / 20
p (x, y).z :=0 endfor endfor end LoadGraphX
proc RotateFormula (var p1, p2 :real, a :real) var p1T := p1 *cosd(a) + p2 *sind(a) var p2T := p2 *cosd(a) - p1 *sind(a)
p1 := p1T
p2 := p2T
end RotateFormula
proc Rotate (var p :array - 18.. 18, -18.. 18of points, x, y, z :real) if x ~=0then for x1 : -18.. 18 for y1 : -18.. 18
RotateFormula (p (x1, y1).x, p (x1, y1).z, x) endfor endfor endif if y ~=0then for x1 : -18.. 18 for y1 : -18.. 18
RotateFormula (p (x1, y1).y, p (x1, y1).z, y)
endfor endfor endif if z ~=0then for x1 : -18.. 18 for y1 : -18.. 18
RotateFormula (p (x1, y1).x, p (x1, y1).y, z) endfor endfor endif end Rotate
proc DrawObject (var p :array - 18.. 18, -18.. 18of points, cx, cy :int) var x, y :int for x1 : -18.. 18 for y1 : -18.. 18
x :=round(p (x1, y1).x / (p (x1, y1).z - 3)* scale) + cx
y :=round(p (x1, y1).y / (p (x1, y1).z - 3)* scale) + cy
Draw.Dot(x, y, 47) endfor endfor end DrawObject
proc DrawGrid
cls Draw.ThickLine(200, 0, 200, 600, 5, 47) Draw.ThickLine(400, 0, 400, 600, 5, 47) Draw.ThickLine(0, 200, 600, 200, 5, 47) Draw.ThickLine(0, 400, 600, 400, 5, 47) for x :1.. 3 for y :1.. 3 if g (x, y).used then if g (x, y).value =1then
DrawObject (px, x *200 - 100, y *200 - 100) else
DrawObject (po, x *200 - 100, y *200 - 100) endif endif endfor endfor View.Update end DrawGrid
function Detection :string var full :boolean:=true for i :1.. 2 if
g (1, 1).value = i and g (1, 2).value = i and g (1, 3).value = i or
g (2, 1).value = i and g (2, 2).value = i and g (2, 3).value = i or
g (3, 1).value = i and g (3, 2).value = i and g (3, 3).value = i or
g (1, 1).value = i and g (2, 1).value = i and g (3, 1).value = i or
g (1, 2).value = i and g (2, 2).value = i and g (3, 2).value = i or
g (1, 3).value = i and g (2, 3).value = i and g (3, 3).value = i or
g (1, 1).value = i and g (2, 2).value = i and g (3, 3).value = i or
g (3, 1).value = i and g (2, 2).value = i and g (1, 3).value = i then result results (i) endif endfor for x :1.. 3 for y :1.. 3 if ~g (x, y).used then result results (0) endif endfor endfor result results (3) end Detection
function Placement (turn :boolean):int if turn then result1 else result2 endif end Placement
LoadGraphX (px)
LoadGraphO (po)
DrawGrid
Mouse.Where(cm, sm, bm) loop Mouse.Where(xm, ym, bm) if bm =1and xm > 0and xm < 600and ym > 0and ym < 600then if ~g (xm div200 + 1, ym div200 + 1).used then
g (xm div200 + 1, ym div200 + 1).used :=true
g (xm div200 + 1, ym div200 + 1).value := Placement (turn)
turn := ~turn
endif endif
DrawGrid
Rotate (px, xm - cm, ym - sm, bm *10)
Rotate (po, xm - cm, ym - sm, bm *10)
cm := xm
sm := ym
exitwhen Detection ~="" endloop Font.Draw(Detection, maxxdiv2 - Font.Width(Detection, font)div2, maxydiv2 - 25, font, 47) View.Update
Sponsor Sponsor
A.J
Posted: Wed Jan 21, 2009 10:18 pm Post subject: Re: Tic Tac Toe with 3D!
I am impressed............kudos
although, you can improve this by converting the whole grid into a cube......consider it as an extension to your program
very good though
Homer_simpson
Posted: Thu Jan 22, 2009 1:04 am Post subject: Re: Tic Tac Toe with 3D!
neat!
seems u've learned 3d programming pretty well in turing, time to move on to more powerful programs like java and c
The_Bean
Posted: Thu Jan 22, 2009 6:58 am Post subject: Re: Tic Tac Toe with 3D!
Actually python for grade 12 which starts in 1 week. And this game was made entirely in 1 class on spare.
Ethan3210
Posted: Thu Jan 22, 2009 8:59 am Post subject: Re: Tic Tac Toe with 3D!
The_Bean @ Thu Jan 22, 2009 6:58 am wrote:
Actually python for grade 12 which starts in 1 week. And this game was made entirely in 1 class on spare.
...
YOU.
ARE.
GOD.
That woulda taken me days. xD
saltpro15
Posted: Thu Jan 22, 2009 9:01 am Post subject: RE:Tic Tac Toe with 3D!
cool, great job
dc116
Posted: Fri Jan 23, 2009 4:39 pm Post subject: RE:Tic Tac Toe with 3D!
I am very impressed with this program. Good work!
Insectoid
Posted: Fri Jan 23, 2009 10:25 pm Post subject: RE:Tic Tac Toe with 3D!
Just a question,
Are you going to go into video games? I assume you'd do well there. Your work is just phenomenal.
I used to do games almost exclusively, but I discovered that programs that are largely technical rather than graphical are more fun. Simulations are cool too.
You can call me your first and biggest fan. Your games have reached cereal box quality. Soon, you may reach CD-that-comes-with-game-magazine-dom. That would be awesome.
Sponsor Sponsor
andrew.
Posted: Fri Jan 23, 2009 10:44 pm Post subject: RE:Tic Tac Toe with 3D!
Great job Bean! It would take me a lot more time than a spare period to write something like that.
The_Bean
Posted: Sat Jan 24, 2009 1:13 am Post subject: Re: Tic Tac Toe with 3D!
Video Games are definitely a field I wouldn't mind ending up in. They combine math, physics, and computers which I love.
I feel like The Flight of the Conchords now that I have a fan base of 1. I might need to get a t-shirts made.
Heres the starting of 3D Tic-Tac-Toe 3*3*3 grid.
Not yet playable, I'm still trying to figure out a method for choosing boxes, and if theres an easier way than hard-coding every possible win scenario.
Turing:
View.Set("graphics:600,600,offscreenonly,nobuttonbar,position:center,center") type grid : record
value :int
used :boolean
x, y, z :real endrecord var g :array1.. 3, 1.. 3, 1.. 3of grid
type coordinates : record
x, y, z :real endrecord type points : record
p :array - 9.. 9, -9.. 9of coordinates
endrecord var Shape :array1.. 2of points
var xm, ym, bm :int var cm, sm :int var objectScale :int:=30 var gridScale :int:=100
fcn RandBoolean :boolean if Rand.Int (0, 1)=1then resulttrue else resultfalse endif end RandBoolean
for x :1.. 3 for y :1.. 3 for z :1.. 3
g (x, y, z).used := RandBoolean
g (x, y, z).value := Rand.Int (1, 2)
g (x, y, z).x := x - 2
g (x, y, z).y := y - 2
g (x, y, z).z := z - 2 endfor endfor endfor
proc LoadGraphO (var d : points) for x : -9.. 9 for y : -9.. 9
d.p (x, y).x :=cosd(x *20)*sind(y *20)
d.p (x, y).y :=sind(x *20)*sind(y *20)
d.p (x, y).z :=cosd(y *20) endfor endfor end LoadGraphO
proc LoadGraphX (var d : points) for x : -9.. 9by2 for y : -9.. 9
d.p (x, y).x := x / 10
d.p (x, y).y :=sind(y)
d.p (x, y).z := y / 10 endfor endfor for x : -8.. 9by2 for y : -9.. 9
d.p (x, y).x := x / 10
d.p (x, y).y := y / 10
d.p (x, y).z :=0 endfor endfor end LoadGraphX
proc RotateFormula (var p1, p2 :real, a :real) var p1T := p1 *cosd(a) + p2 *sind(a) var p2T := p2 *cosd(a) - p1 *sind(a)
p1 := p1T
p2 := p2T
end RotateFormula
proc Rotate (x, y, z :real) for n :1.. 2 for x1 : -9.. 9 for y1 : -9.. 9
RotateFormula (Shape (n).p (x1, y1).x, Shape (n).p (x1, y1).z, x)
RotateFormula (Shape (n).p (x1, y1).y, Shape (n).p (x1, y1).z, y)
RotateFormula (Shape (n).p (x1, y1).x, Shape (n).p (x1, y1).y, z) endfor endfor endfor for x1 :1.. 3 for y1 :1.. 3 for z1 :1.. 3
RotateFormula (g (x1, y1, z1).x, g (x1, y1, z1).z, x)
RotateFormula (g (x1, y1, z1).y, g (x1, y1, z1).z, y)
RotateFormula (g (x1, y1, z1).x, g (x1, y1, z1).y, z) endfor endfor endfor end Rotate
proc DrawObject (d : points, x, y, z :int) var x2, y2 :int for x1 : -9.. 9 for y1 : -9.. 9
x2 :=round((g (x, y, z).x * gridScale) + (d.p (x1, y1).x * objectScale) + 300)
y2 :=round((g (x, y, z).y * gridScale) + (d.p (x1, y1).y * objectScale) + 300) Draw.Dot(x2, y2, RGB.AddColour(x / 3, y / 3, z / 3)) endfor endfor end DrawObject
proc DrawGrid
cls for x :1.. 3 for y :1.. 3 for z :1.. 3 if g (x, y, z).value ~=0then
DrawObject (Shape (g (x, y, z).value), x, y, z) endif endfor endfor endfor View.Update end DrawGrid
LoadGraphX (Shape (1))
LoadGraphO (Shape (2)) Mouse.Where(cm, sm, bm) loop Mouse.Where(xm, ym, bm)
DrawGrid
Rotate (xm - cm, ym - sm, bm *10)
cm := xm
sm := ym
exitwhenhasch endloop
A.J
Posted: Sat Jan 24, 2009 10:58 am Post subject: RE:Tic Tac Toe with 3D!
cool, I see you have taken my advice
Good job, you are heading in the right direction. But just one small thing though : don't make the cube move as your mouse moves...that'll make it hard for the player to choose a position for his piece.
The_Bean
Posted: Sat Jan 24, 2009 12:35 pm Post subject: Re: Tic Tac Toe with 3D!
The rotating with the mouse was just for show, I've already remapped the rotation of the x/o's and the grid to the keyboard.
I'm thinking of having a secondary grid showing the 27 squares, which you can click on. Clicking on the cube would be hard to get the center box.
Also when you hover over them they will highlight on the cube to show where that is.
Insectoid
Posted: Sat Jan 24, 2009 1:10 pm Post subject: RE:Tic Tac Toe with 3D!
Only idea I have for checking wins is to have multiple nested for loops (x, y, z) for the horizontal/vertical wins and do that several times, with slight modification of the condition to find a win.
I'm sure some will have to be hard-coded.
The_Bean
Posted: Sun Jan 25, 2009 12:36 am Post subject: Re: Tic Tac Toe with 3D!
I'm pretty sure i got the detection working, I can only think of 49 ways to win. Because of how easy it is to win, I went with the idea that you get a point for each line of 3 you make. The winner is the player with the most points when the board is full.
Controls
A,D-rotate board left/right
W,X-rotate board up/down
S-Spin board
F,H-rotate objects left/right
T,B-rotate objects up/down
G-Spin Objects
Use the lower left grids to pick your move.
Not done yet, but the inner workings are complete. Just looks and feel left to go.
Download file this time since I don't think I should post 231 lines.
Posted: Sun Jan 25, 2009 11:51 am Post subject: Re: Tic Tac Toe with 3D!
it is getting along pretty well
2 small things that you might want to add :
1). The board (i.e. draw the cube where the pieces are held)
2). Try changing the gameplay so that if u get 1 3-in-a-row, u win the game (although tat might be a little rigged for player 1...)