[gnome-sudoku] Change some stuff



commit 1323f7f499e5900e981ed88c18b017af93764ddb
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Tue Aug 5 20:43:22 2014 -0500

    Change some stuff
    
    This is a horrible commit. Never do this.
    
    * Rename files
    * Style changes
    * Fix two memory leaks

 Makefile.am                                |    3 +-
 lib/Makefile.am                            |   10 ++--
 lib/QQwing-client.vapi                     |    6 --
 lib/QQwing-wrapper.cpp                     |   70 --------------------------
 lib/qqwing-wrapper.cpp                     |   75 ++++++++++++++++++++++++++++
 lib/{QQwing-wrapper.h => qqwing-wrapper.h} |    9 +++-
 lib/qqwing.vapi                            |    6 ++
 7 files changed, 95 insertions(+), 84 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 0e1da46..d14c07e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5,6 +5,7 @@ ACLOCAL_AMFLAGS = -I m4
 MAINTAINERCLEANFILES = \
        $(GITIGNORE_MAINTAINERCLEANFILES_TOPLEVEL) \
        $(GITIGNORE_MAINTAINERCLEANFILES_MAKEFILE_IN) \
-       $(GITIGNORE_MAINTAINERCLEANFILES_M4_LIBTOOL)
+       $(GITIGNORE_MAINTAINERCLEANFILES_M4_LIBTOOL) \
+       m4/
 
 -include $(top_srcdir)/git.mk
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 9e0d3ca..e0af6eb 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -3,11 +3,11 @@ noinst_LTLIBRARIES = libsudoku.la
 libsudoku_la_SOURCES = \
        sudoku-board.vala \
        sudoku-game.vala \
-       sudoku-saver.vala       \
-       sudoku-generator.vala   \
-       QQwing-client.vapi      \
-       QQwing-wrapper.cpp      \
-       QQwing-wrapper.h
+       sudoku-saver.vala \
+       sudoku-generator.vala \
+       qqwing.vapi \
+       qqwing-wrapper.cpp \
+       qqwing-wrapper.h
 
 libsudoku_la_CFLAGS = -w
 
diff --git a/lib/qqwing-wrapper.cpp b/lib/qqwing-wrapper.cpp
new file mode 100644
index 0000000..77c4d8a
--- /dev/null
+++ b/lib/qqwing-wrapper.cpp
@@ -0,0 +1,75 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * Copyright © 2014 Parin Porecha
+ *
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 2 of the License, or (at your option) any later
+ * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
+ * license.
+ */
+
+#include "qqwing-wrapper.h"
+
+#include <algorithm>
+#include <iostream>
+
+#include <glib.h>
+#include <qqwing.hpp>
+
+using namespace qqwing;
+using namespace std;
+
+/*
+ * Generate a symmetric puzzle of specified difficulty.
+ */
+int* qqwing_generate_puzzle(int difficulty)
+{
+    int i = 0;
+    const int MAX_ITERATIONS = 1000;
+    const int BOARD_SIZE = 81;
+    SudokuBoard board;
+
+    board.setRecordHistory(true);
+    board.setLogHistory(false);
+    board.setPrintStyle(SudokuBoard::ONE_LINE);
+
+    for (i = 0; i < MAX_ITERATIONS; i++)
+    {
+        bool havePuzzle = board.generatePuzzleSymmetry(SudokuBoard::RANDOM);
+        board.solve();
+        if (havePuzzle && static_cast<SudokuBoard::Difficulty>(difficulty) == board.getDifficulty())
+            break;
+    }
+
+    if (i == MAX_ITERATIONS)
+        g_error("Could not generate puzzle of specified difficulty. I tried so hard. Please report at 
bugzilla.gnome.org.");
+
+    const int* original = board.getPuzzle();
+    int* copy = new int[BOARD_SIZE];
+    std::copy(original, &original[BOARD_SIZE], copy);
+    return copy;
+}
+
+/*
+ * Print the stats gathered while solving the puzzle given as input.
+ */
+void qqwing_print_stats(int* puzzle)
+{
+    SudokuBoard board;
+    board.setRecordHistory(true);
+    board.setLogHistory(false);
+    board.setPuzzle(puzzle);
+    board.solve();
+
+    cout << "Number of Givens: " << board.getGivenCount() << endl;
+    cout << "Number of Singles: " << board.getSingleCount() << endl;
+    cout << "Number of Hidden Singles: " << board.getHiddenSingleCount() << endl;
+    cout << "Number of Naked Pairs: " << board.getNakedPairCount() << endl;
+    cout << "Number of Hidden Pairs: " << board.getHiddenPairCount() << endl;
+    cout << "Number of Pointing Pairs/Triples: " << board.getPointingPairTripleCount() << endl;
+    cout << "Number of Box/Line Intersections: " << board.getBoxLineReductionCount() << endl;
+    cout << "Number of Guesses: " << board.getGuessCount() << endl;
+    cout << "Number of Backtracks: " << board.getBacktrackCount() << endl;
+    cout << "Difficulty: " << board.getDifficultyAsString() << endl;
+}
diff --git a/lib/QQwing-wrapper.h b/lib/qqwing-wrapper.h
similarity index 77%
rename from lib/QQwing-wrapper.h
rename to lib/qqwing-wrapper.h
index 2ef7185..42c683a 100644
--- a/lib/QQwing-wrapper.h
+++ b/lib/qqwing-wrapper.h
@@ -9,11 +9,16 @@
  * license.
  */
 
+#ifndef QQWING_WRAPPER_H
+#define QQWING_WRAPPER_H
+
 #include <glib.h>
 
 G_BEGIN_DECLS
 
-const int* qqwing_generate_puzzle(int difficulty);
-void qqwing_print_stats(int *initPuzzle);
+int *qqwing_generate_puzzle(int difficulty);
+void qqwing_print_stats(int *puzzle);
 
 G_END_DECLS
+
+#endif
diff --git a/lib/qqwing.vapi b/lib/qqwing.vapi
new file mode 100644
index 0000000..27d4888
--- /dev/null
+++ b/lib/qqwing.vapi
@@ -0,0 +1,6 @@
+[CCode (cheader_filename = "qqwing-wrapper.h")]
+namespace QQwing {
+    [CCode (array_length=false)]
+    int[] generate_puzzle (int difficulty);
+    void print_stats ([CCode (array_length = false)] int[] puzzle);
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]