Java TicTacToe - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Java TicTacToe

wayne_runswayne_runs Posts: 4Member
Could someone please help me complete the following code. Now I know there are lots of TicTacToe programs out there but they're using a lot of code in which I can't use to complete this program. To complete this program I need to use basic simple Java langauge.

Now I have done some of the code but there is still some I am really struggling to complete. Please could someone help me out.

[code]class Rows {

// computes an array "rows" of length r, each element an array "line" of
// length k, whose elements are arrays of length 2: array line represents a
// "row" of an m x n field, and array rows collects precisely all these
// lines; for efficient array-allocation (upfront) the precise number r of
// rows must also be given:

public static int[][][] list_rows(final int k, final int m, final int n, final int r) {
assert(k >= 2);
assert(m >= 1);
assert(n >= 1);
assert(k <= m || k <= n);
assert(r >= 1); int[][][] rows = new int[r][][];
int row_index = 0;
// I need to complete this!
assert(row_index == r);
return rows;
public static boolean check_list_rows(final int[][][] lr, final int[][] field) {
if (lr == null) return false;
final int R = lr.length;
if (R == 0) return false;
if (lr[0] == null) return false;
final int K = lr[0].length;
if (K == 0) return false;
for (int r = 0; r < R; ++r) {
if (lr[r] == null) return false;
if (lr[r].length != K) return false;
for (int p = 0; p < K; ++p) {
if (lr[r][p] == null) return false;
if (lr[r][p].length != 2) return false;
if (! Field.valid_coordinates(field, lr[r][p][0]+1, lr[r][p][1]+1)) return false;
return true;
public static void main(final String[] args) {
final int K = Integer.parseInt(args[0]);
final int M = Integer.parseInt(args[1]);
final int N = Integer.parseInt(args[2]);
final int R = Counting.number_rows(K,M,N);
final int[][][] rows = list_rows(K,M,N,R);
for (int r = 0; r < R; ++r) {
System.out.print(r + ": ");
for (int p = 0; p < K; ++p)
System.out.print("(" + rows[r][p][0] + "," + rows[r][p][1] + ")");
} [/code]

Thank you very much!
Sign In or Register to comment.