[Picross-commit] SF.net SVN: picross: [56] trunk/src/picross/grid
Status: Pre-Alpha
Brought to you by:
yvan_norsa
From: <yva...@us...> - 2008-04-18 12:58:01
|
Revision: 56 http://picross.svn.sourceforge.net/picross/?rev=56&view=rev Author: yvan_norsa Date: 2008-04-18 05:58:07 -0700 (Fri, 18 Apr 2008) Log Message: ----------- marks empty rows and columns as completed Modified Paths: -------------- trunk/src/picross/grid/CompletedHints.java trunk/src/picross/grid/GridModel.java Modified: trunk/src/picross/grid/CompletedHints.java =================================================================== --- trunk/src/picross/grid/CompletedHints.java 2008-04-18 11:55:47 UTC (rev 55) +++ trunk/src/picross/grid/CompletedHints.java 2008-04-18 12:58:07 UTC (rev 56) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (c) 2007 + * Copyright (c) 2007-2008 * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, @@ -152,6 +152,17 @@ } /** + * Marks a whole column as complete. + * + * @param col column number + */ + void setCompleteCol(int col) { + for (int i = 0; i < this.completedCols[col].length; i++) { + this.setCompleteColHint(col, i); + } + } + + /** * Tells wether a specific row hint is complete. * * @param x row number @@ -190,7 +201,6 @@ return res; } - /** * Resets the state of a hint. * @@ -210,5 +220,16 @@ void setCompleteRowHint(int row, int index) { this.completedRows[row][index] = true; } + + /** + * Marks a whole row as complete. + * + * @param row row number + */ + void setCompleteRow(int row) { + for (int i = 0; i < this.completedRows[row].length; i++) { + this.setCompleteRowHint(row, i); + } + } } Modified: trunk/src/picross/grid/GridModel.java =================================================================== --- trunk/src/picross/grid/GridModel.java 2008-04-18 11:55:47 UTC (rev 55) +++ trunk/src/picross/grid/GridModel.java 2008-04-18 12:58:07 UTC (rev 56) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (c) 2007 + * Copyright (c) 2007-2008 * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, @@ -36,7 +36,7 @@ import java.util.ArrayList; import java.util.List; -//import org.apache.log4j.Logger; +import org.apache.log4j.Logger; /** * The grid model. @@ -52,7 +52,7 @@ /*** Static field ***/ /** The class' logger. */ - //private static Logger log = Logger.getLogger(GridModel.class); + private static Logger log = Logger.getLogger(GridModel.class); /*** Fields ***/ @@ -260,6 +260,20 @@ this.completedHints = new CompletedHints(data.length, this.colData[0].length, data[0].length, this.rowData[0].length); + + // Marks the empty rows and columns as completed + + for (int i = 0; i < this.rowData.length; i++) { + if (this.emptyRow(i)) { + this.completedHints.setCompleteRow(i); + } + } + + for (int i = 0; i < this.colData.length; i++) { + if (this.emptyCol(i)) { + this.completedHints.setCompleteCol(i); + } + } } /*** Static methods ***/ @@ -414,11 +428,29 @@ } /** + * Checks if a row is empty. + * + * @param row row number + * @return boolean stating wether the row is empty or not + */ + private boolean emptyRow(int row) { + int index = this.getFirstHintIndex(this.rowData[row]); + + return (index == this.getLastHintIndex(this.rowData[row])) + && (this.rowData[row][index] == 0); + } + + /** * Checks if a hint has been completed in a row. * * @param row row number to check */ private void checkRow(int row) { + if (this.emptyRow(row)) { + this.completedHints.setCompleteRow(row); + return; + } + // Contains the completed hints List<Integer> completedRowHints = new ArrayList<Integer>(); @@ -553,6 +585,19 @@ } /** + * Checks if a column is empty. + * + * @param col column number + * @return boolean stating wether the column is empty or not + */ + private boolean emptyCol(int col) { + int index = this.getFirstHintIndex(this.colData[col]); + + return (index == this.getLastHintIndex(this.colData[col])) + && (this.colData[col][index] == 0); + } + + /** * Checks if a hint has been completed in a column. * * @param column column number to check @@ -560,6 +605,11 @@ private void checkColumn(int column) { //GridModel.log.debug("checkColumn(" + column + ")"); + if (this.emptyCol(column)) { + this.completedHints.setCompleteCol(column); + return; + } + List<Integer> completedColHints = new ArrayList<Integer>(); /* for (int i = 0; i < this.colData[column].length; i++) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |