Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

TicTacToe program

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to make a program that allows two players to play tictactoe. The game board has to be done using ASCII, which I've already done. However, since it's not an array with indexes, how do I access each place on the board?..for example if the player wants to place an X on row 3, column 2...?
 
Marshal
Posts: 25682
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the board isn't an array with indexes, then what is it? There's no way for anybody to know how to access data from a "board" when all we know about it is its name.
 
Ranch Hand
Posts: 49
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its ASCII Paul

Which i guess could easily be represented by Strings, 1 String represents 1 Line of the board.



If its something like that, then your row is String1, String2 or String3, and your "column"
is Character of index '1', '3' or '5' in that string.

Im sure there are much more elegant and flexible ways, but if i'd have to do it quick&dirty,
i.e. for testing if the rest of the program works, i'd do it this way.

 
Saloon Keeper
Posts: 12161
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's much better to use an array of an enum type. Then you can very simply change the board, and if you need ASCII you can let the TicTacToe class convert the board to a String in its toString() method.
 
Too many men are afraid of being fools - Henry Ford. Foolish tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic