0
我們正在運行棋盤遊戲模擬器,我們需要計算機在陣列(棋盤)中選擇0-5之間的隨機位置(所有這些都完成),我們實現了一個數組player1move,用於存儲計算機的移動但是如果隨機值選擇一個空的位置,我們會打印出「錯誤,請再次移動」,但移動會被添加到movehist數組中,儘管是非法移動。任何人想到解析這個隨機int的好方法?檢查隨機Ints?
int player1move;
Random rand1 = new Random();
player1move = rand1.nextInt(6);
System.out.println("\nPlayer 1, Your move:");
int h = 0;
int i = player1move;
player1array.add(i);
System.out.println(player1array);
h = h+1;
你的描述非常混亂。簡單地選擇*總是*一個非空的正確位置是否可行? – 2013-03-27 14:47:39