working on use input board size.

This commit is contained in:
RustyRaptor committed 2019-05-23 17:07:25 -06:00
1 parent ae0a606ddc
commit 2316a27541
1 file changed
+10 -9
+10 -9
View File
@@ -4,10 +4,11 @@ import std.range : iota;
import std.random;
import std.datetime;
import std.datetime.timezone : LocalTime;
import core.simd;
/// Prints the board
void printBoard(int[5][5] board){
void printBoard(int[][] board){
/// TODO: print neatly
foreach(row; board) {
writeln(row);
@@ -20,31 +21,31 @@ void printWelcome(){
}
/// returns a random row on the game board
int randomRow(){
int randomRow(int[][] board){
auto rnd = Random();
/// TODO: range based on length of board
const int i = uniform(0, 4, rnd);
const int i = uniform(0, board.length, rnd);
assert(i >= 0 && i < 4);
return(i);
}
/// returns a random column on the game board
int randomCol(){
int randomCol(int[][] board){
auto rnd = Random(22);
/// TODO: range based on length of board
const int i = uniform(0, 4, rnd);
const int i = uniform(0, board.length, rnd);
assert(i >= 0 && i < 4);
return(i);
}
void main(){
const int a = 5;
/// Initialize the board
/// TODO: User inputs size of board
int[5][5] board;
foreach(row; board) {
foreach(item; row){
item = 0;
@@ -53,8 +54,8 @@ void main(){
SysTime today = Clock.currTime();
writeln(((today.second)));
/// place a ship on a random tile
const int shipRow = randomRow();
const int shipCol = randomCol();
const int shipRow = randomRow(board);
const int shipCol = randomCol(board);
printWelcome();
printBoard(board);
// writeln(board[shipRow]);