This site requires JavaScript, please enable it in your browser!
Greenfoot back
arumsari
arumsari wrote ...

2026/6/28

need help

arumsari arumsari

2026/6/28

#
import greenfoot.*; public class Sudoku extends World { // Pola Sudoku awal berdasarkan slide kuliah (0 berarti kosong) private int board = { {5, 3, 0, 0, 7, 0, 0, 0, 0}, {6, 0, 0, 1, 9, 5, 0, 0, 0}, {0, 9, 8, 0, 0, 0, 0, 6, 0}, {8, 0, 0, 0, 6, 0, 0, 0, 3}, {4, 0, 0, 8, 0, 3, 0, 0, 1}, {7, 0, 0, 0, 2, 0, 0, 0, 6}, {0, 6, 0, 0, 0, 0, 2, 8, 0}, {0, 0, 0, 4, 1, 9, 0, 0, 5}, {0, 0, 0, 0, 8, 0, 0, 7, 9} }; public Sudoku() { // Ukuran cell disesuaikan dengan pixel grid pada gambar .jpg dosen super(9, 9, 50); // Pasang gambar template sebagai background setBackground("sudoku_board.jpg"); prepareBoard(); } private void prepareBoard() { for (int r = 0; r < 9; r++) { for (int c = 0; c < 9; r++) { // Jika infinity loop, pastikan c++ } } // Koreksi loop penempatan cell agar presisi 9x9 for (int r = 0; r < 9; r++) { for (int c = 0; c < 9; c++) { int val = board; Cell cell = new Cell(); addObject(cell, c, r); if (val != 0) { cell.setNumber(val); } } } } // Validasi baris: dipanggil setiap kali ada cell yang berubah nilainya public boolean isValidRow(int row, int num) { int count = 0; java.util.List<Cell> cells = getObjects(Cell.class); for (Cell c : cells) { if (c.getY() == row && c.getNumber() == num) { count++; } } return count <= 1; } }
danpost danpost

2026/6/28

#
arumsari wrote...
need help << Code Omitted >>
The only thing I see wrong with your codes is in the second line of the prepareBoard method, which should increment the column (c) value, not the row (r) value. Don't really know what you need help with. You need to explain (in English, please) what you are trying to do and how the execution is wrong.
You need to login to post a reply.