
-----------------------------------
Insectoid
Sun Apr 19, 2009 6:39 pm

mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
Well, I've had an idea bouncing around in my head to create a game of Tic-Tac-Toe with no conditionals. That means no if-statements, case-statements, exit-statements, etc. The only selection you can use is in the case of for loops, for example;

for (int i = 0, i>= 5, i++){
}

Being the lazy bum I am, I haven't gotten around to it. However, I believe that clever use of hashes, math, and binary should do the trick. So I'm challenging you guys to do this (mostly so I can see the finished product without actually doing it). The requirements:

-it must have a visual display. Be it ASCII or 3-D, it must have a graphical representation of where the X's and O's are. 
-it must follow standard 3x3 tic-tac-toe rules
-it must be multiplatform (Turing is okay, it runs perfectly on Wine and Crossover)
-it must not use and conditionals, except in the case of for loops as shown above
-it must display the name/player number of the winner when a player wins
-it need not have a mouse implementation, you may enter the location of your X or O via coordinates. 


Have fun! Winner gets 1000 bits (unless I don't have that many...)


EDIT: The winner is the person who makes the most interesting program, and has the most awesome code (judged by me)

-----------------------------------
saltpro15
Sun Apr 19, 2009 7:00 pm

RE:mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
damn that's a challenge... I'll give it a shot, how long do we have?

-----------------------------------
Insectoid
Sun Apr 19, 2009 7:03 pm

RE:mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
You have until whenever I say so, aka whenever I get bored of waiting.

And those for loop conditionals can only be used in counted loops. A 'do this X many times' loop. No sneaky rule-bending allowed.

-----------------------------------
saltpro15
Sun Apr 19, 2009 7:21 pm

RE:mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
hehe very well, I'll be getting ready for ECOO all this week, so I'll have some time to start it hopefully

-----------------------------------
Nick
Sun Apr 19, 2009 7:44 pm

Re: mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
Done Python style

class Board:
    def __init__ (self):
        self.p = 

also Saad caught me cheating so this doesn't count, oh well

-----------------------------------
Brightguy
Mon Apr 20, 2009 8:54 am

Re: mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
function won()
{	var m = marks

-----------------------------------
Insectoid
Mon Apr 20, 2009 3:37 pm

RE:mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
wew, brightguy, that's fancy. I'm gonna have to ask somebody who understands javascript to look it over for cheating (not that I accuse you, but because you may have coded some in by habit). God, javascript's method names are so ridiculously long it's harder to understand than one with short names (ie ruby/python).

EDIT: Neither submissions handles cat's game. Definitely points for that.

-----------------------------------
Insectoid
Mon Apr 20, 2009 4:09 pm

RE:mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
Just a question;

[code]
{       var m = marks[turn];
        return (m[0]&m[1]&m[2])|(m[3]&m[4]&m[5])|(m[6]&m[7]&m[8])|(m[0]&m[3]&m[6])|(m[1]&m[4]&m[7])|(m[2]&m[5]&m[8])|(m[0]&m[4]&m[8])|(m[2]&m[4]&m[6]); 
[/code]

Does that big return statement mean 'return (1 and 2 and 3) or (3 and 4 and 5) or (6 and 7 and 8)...'?

-----------------------------------
Nick
Mon Apr 20, 2009 4:27 pm

RE:mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
EDIT: Neither submissions handles cat's game. Definitely points for that. mine does....

-----------------------------------
Alexmula
Mon Apr 20, 2009 5:23 pm

Re: mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
import os
os.startfile("http://www.prongo.com/tictac/")



 :lol:  :lol:  :lol:

-----------------------------------
Insectoid
Mon Apr 20, 2009 5:24 pm

RE:mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
no.

-----------------------------------
richcash
Mon Apr 20, 2009 6:10 pm

Re: mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
Here is an unspectacular Tic Tac Toe with no conditionals in Turing. I might polish the display if I have more time.

View.Set ("offscreenonly")
var w, winner, turn, sel := 0
var board : array 0 .. 2, 0 .. 2 of int := init (0, 0, 0, 0, 0, 0, 0, 0, 0)
var names : array - 1 .. 1 of string := init ("x", "-", "y")
turn := -1
loop
    cls
    put names (winner), " won"
    w := round (sqrt (-abs (winner)))
    for i : 0 .. 2
        for j : 0 .. 2
            locate (i * 2 + 3, j * 2 + 1)
            put names (board (i, j))
        end for
    end for
    put names (turn), " enter a number from 1-9."
    View.Update
    sel := strint (getchar) - 1
    board (sel div 3, sel mod 3) := sign (board (sel div 3, sel mod 3) * 2 + turn)
    turn := 0
    for i : 0 .. 2
        for j : 0 .. 2
            turn += board (i, j)
        end for
    end for
    turn := turn * -2 - 1
    winner := 0
    w := 0
    for i : 0 .. 2
        for j : 0 .. 2
            w += board (i, j)
        end for
        winner += w div 3
        w := 0
    end for
    for i : 0 .. 2
        for j : 0 .. 2
            w += board (j, i)
        end for
        winner += w div 3
        w := 0
    end for
    for i : 0 .. 2
        w += board (i, i)
    end for
    winner += w div 3
    w := 0
    for i : 0 .. 2
        w += board (i, 2 - i)
    end for
    winner += w div 3
end loop

-----------------------------------
The_Bean
Mon Apr 20, 2009 7:34 pm

Re: mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
Python 2.5.4:

def getNothing(person):
    return 10

def board():
    print '\n\n',grid

-----------------------------------
CodeMonkey2000
Mon Apr 20, 2009 8:29 pm

RE:mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
I'm waiting for someone to write this in BF. Hehehe.

-----------------------------------
richcash
Mon Apr 20, 2009 9:38 pm

Re: mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
Just a question;

Yes, but he is using them as bitwise operators not boolean operators, so he is not using selection directly.

@The_Bean, good job but I would consider the function filter a conditional/selection method. In fact, you can probably replace every single if statement by using filter trivially.

@Nick, do you mind telling us why your code is supposedly invalid (I don't read python well).

-----------------------------------
matt271
Tue Apr 21, 2009 5:31 am

RE:mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
/* 
 * File:   newmain.cpp
 * Author: matt
 *
 * Created on April 21, 2009, 7:06 AM
 */

#include 
#include 
using namespace std;

int board

enter the quardenents from 0 to 2 separated by spaces.

should look like:

0 0

X _ _
_ _ _
_ _ _

0 1

X O _
_ _ _
_ _ _

1 1

X O _
_ X _
_ _ _

0 2

X O O
_ X _
_ _ _

2 2

X O O
_ X _
_ _ X

X wins

-----------------------------------
Nick
Tue Apr 21, 2009 1:36 pm

Re: mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
@Nick, do you mind telling us why your code is supposedly invalid (I don't read python well).

I used a for i in range (x): loop as an if x: statement

ex:
[code]for i in range (self.p [x][y] != 0): [/code]

-----------------------------------
matt271
Tue Apr 21, 2009 4:21 pm

RE:mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
no comment on my solution? :(

-----------------------------------
richcash
Tue Apr 21, 2009 4:59 pm

Re: mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
I used a for i in range (x): loop as an if x: statement

ex:
Ah, I see, I somehow missed that.


no comment on my solution? (Looks good to me, though I don't have a compiler at the moment to test it. However :
t = boardI think you forgot to check for vertical wins, if I'm not mistaken. Am I right?

-----------------------------------
matt271
Tue Apr 21, 2009 6:00 pm

Re: mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
my bad :] i fixed it ty

/* 
 * File:   newmain.cpp
 * Author: matt
 *
 * Created on April 21, 2009, 7:06 AM
 */

#include 
#include 
using namespace std;

int board

and in java!


import java.util.Scanner;


/**
 *
 * @author matt
 */
public class Main {

    static int

-----------------------------------
Nick
Wed Apr 22, 2009 2:54 am

RE:mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
here's a comment, where's cat's game and where's the code that stops you from playing where one's already played?

-----------------------------------
matt271
Wed Apr 22, 2009 3:46 am

RE:mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
what is cats game? 

and nothing stops u from playing where some1 already played. 

also nothing stops u from giving a point off the 3x3 grid

and nothing stops u from playing after u already won (but the java one will tell u the game is already over :D)

i guess i could come up w/ some real clever way to do those

but i still think i won, i want the bits (what r bits anyways?)

its all for fun :]

-----------------------------------
matt271
Wed Apr 22, 2009 4:22 am

Re: mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
there i did it in c this time:

/* 
 * File:   newmain.c
 * Author: matt
 *
 * Created on April 22, 2009, 5:54 AM
 */

#include 
#include 

void valid();
void notvalid();
void showboard();
int test();
void none();
void win();
void clearboard();

int board

input ur moves the same

output is liek this

1 1

_ _ _
_ X _
_ _ _

0 1

_ O _
_ X _
_ _ _

0 0

X O _
_ X _
_ _ _

0 2

X O O
_ X _
_ _ _

2 2

X O O
_ X _
_ _ X

X wins!

0 0

X _ _
_ _ _
_ _ _

1 0

X _ _
O _ _
_ _ _

0 1

X X _
O _ _
_ _ _

1 1

X X _
O O _
_ _ _

0 2

X X X
O O _
_ _ _

X wins!

2 2

_ _ _
_ _ _
_ _ X

0 0

O _ _
_ _ _
_ _ X

2 1

O _ _
_ _ _
_ X X

0 2

O _ O
_ _ _
_ X X

1 1

O _ O
_ X _
_ X X

0 1

O O O
_ X _
_ X X

O wins!

1 1

_ _ _
_ X _
_ _ _

1 1
Sorry not valid move my friend

_ _ _
_ X _
_ _ _

0 1

_ O _
_ X _
_ _ _

-----------------------------------
OneOffDriveByPoster
Wed Apr 22, 2009 9:19 am

Re: mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------

    void (*fun
I don't know about the contest judge, but this looks like cheating.
An array of function pointers?  That's not a selection statement?  Really?

-----------------------------------
Insectoid
Wed Apr 22, 2009 12:55 pm

RE:mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
I dunno how that works (not knowing any C) but if OneOffDriveByPoster thinks it's cheating, I'll trust him. 

Anyway, if anyone wants to vote on a submission, PM me. Don't vote for your own, it's not cool.

-----------------------------------
richcash
Wed Apr 22, 2009 1:48 pm

Re: RE:mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
what is cats game? When the game ends in a draw.

and nothing stops u from playing where some1 already played. 

and nothing stops u from playing after u already won (but the java one will tell u the game is already over :D)

i guess i could come up w/ some real clever way to do thoseIn my opinion you need to fix those things to make it valid. Also, if the person enters an invalid move (or enters a cell that's already filled) it should still be their turn, but the board should not change.



Anyway, if anyone wants to vote on a submission, PM me. Don't vote for your own, it's not cool.The contest is closed already? The only two completely valid submissions so far are mine and Brightguy's, until matt disallows letting a player enter a cell that's already occupied (since that is a rule of TTT) and Nick, The_Bean get rid of their use of selection.

-----------------------------------
matt271
Wed Apr 22, 2009 2:41 pm

Re: RE:mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
In my opinion you need to fix those things to make it valid. Also, if the person enters an invalid move (or enters a cell that's already filled) it should still be their turn, but the board should not change.

i did fix that in my latest submission :P

I dunno how that works (not knowing any C) but if OneOffDriveByPoster thinks it's cheating, I'll trust him. 

its not cheating  :cry: its not a conditional statement its just a very clever way to call functions :cry:

its no dif then when i said printf(msg[blah]);

-----------------------------------
OneOffDriveByPoster
Wed Apr 22, 2009 2:55 pm

Re: RE:mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
its no dif then when i said printf(msgAbsolutely not.  This can alter control flow (as opposed to the data).

-----------------------------------
matt271
Wed Apr 22, 2009 4:05 pm

RE:mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
but the point was to find a way to build the game w/out condition statements, not w/out flow.

if u say anything that can alter flow is a conditional statement, then any clever way to build the game is a conditional statement.

what if u wrote it in basic and used clever numbers to represent X and O then said GOTO X

blah this was supposed to be a fun lil challenge but now its turning un-fun :cry:

-----------------------------------
OneOffDriveByPoster
Wed Apr 22, 2009 10:11 pm

Re: mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
Cat's game and invalid move checking included.
#include 
#include 

using namespace std;

enum { MAX_BITS = CHAR_BIT * sizeof(unsigned) };  // compile time constant

unsigned isZero

-----------------------------------
Insectoid
Thu Apr 23, 2009 4:03 pm

RE:mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
No, the contest isn't closed. I'm just accepting votes over PM to help me decide who wins. 

When you PM me, include who you're voting for and why their submission is the best.

-----------------------------------
matt271
Thu Apr 23, 2009 6:51 pm

RE:mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
has any1 voted for me? :]

-----------------------------------
saltpro15
Thu Apr 23, 2009 7:54 pm

RE:mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
yeah, sorry insectoid but I really need to get ready for ECOO and do my homework, I don't have the time for this.  I wish i did though :(

-----------------------------------
Insectoid
Thu Apr 23, 2009 7:58 pm

RE:mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
Awh, oh well, saltpro.  Nobody has voted yet, matt.

-----------------------------------
Insectoid
Sat Apr 25, 2009 6:31 pm

RE:mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
All right, looks like all the submissions are in. Contest Closed! Vote on your favorite submission via PM to me! Be sure to include why you voted for that submission!

-----------------------------------
bugzpodder
Sun Apr 26, 2009 8:58 am

Re: RE:mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
wew, brightguy, that's fancy. I'm gonna have to ask somebody who understands javascript to look it over for cheating (not that I accuse you, but because you may have coded some in by habit). God, javascript's method names are so ridiculously long it's harder to understand than one with short names (ie ruby/python).

EDIT: Neither submissions handles cat's game. Definitely points for that.

ROFL

-----------------------------------
matt271
Thu Apr 30, 2009 12:04 am

RE:mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
i vote for myself :D i feel my clever use of an array is in no way even close to a switch statement :D

-----------------------------------
matt271
Thu May 07, 2009 2:11 pm

RE:mini-contest: No selection-structure Tic-Tac-Toe
-----------------------------------
what happened to this contest?

u got any more interesting contests :D
