Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
94f97b5
Started rewriting
rouanth Jul 14, 2016
6990483
Merge the new user interface
rouanth Nov 10, 2016
5e91138
Implemented splitting the graph components
rouanth Nov 10, 2016
d160151
Improve unit tests
rouanth Nov 15, 2016
bb37723
Fix a typo, less redundant unit tests
rouanth Nov 15, 2016
88703c0
Index set is returned with graph components
rouanth Nov 15, 2016
5b041c2
More optimal splitting index
rouanth Nov 15, 2016
73f4706
Fix indentation
rouanth Nov 15, 2016
f5207ce
Implement a function that calls the solver
rouanth Nov 15, 2016
968d803
Implement displaying of results of calculation
rouanth Nov 15, 2016
d2992b7
Fix operation that determines if cells are near
rouanth Nov 15, 2016
7431d5a
Multiple fixes to algorithm
rouanth Nov 16, 2016
c840a5b
Enhance unit tests for algorithm
rouanth Nov 17, 2016
4d365a8
Start implementing generation of fields
rouanth Nov 22, 2016
79f3a4b
Implement better field generator
rouanth Nov 22, 2016
e183fc1
Add more utility functions
rouanth Nov 23, 2016
d41a9f9
Add combination computation and merge functions
rouanth Dec 12, 2016
7bd364c
More general traversal of possibilities
rouanth Dec 12, 2016
c5f96c4
Move array merging and combination listing to util
rouanth Dec 13, 2016
9ba3f84
solver is an object now
rouanth Dec 13, 2016
c61a067
Fix errors made while moving `combinations_arr`
rouanth Dec 13, 2016
9cd5d10
Make debug logging conditional
rouanth Dec 13, 2016
aa79cc6
Better colors
rouanth Dec 13, 2016
c75a551
Fix tests
rouanth Dec 14, 2016
315a8a3
Merge branch 'gh-pages' into solver_rewrite
rouanth Dec 15, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions classes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function Sweep(width, height, mines) {
this.mines = +mines;
this.field = create_matrix(height, width,
function() { return new Cell('q') });
}

function Cell(type) {
function is_of_type (type) {
return function () {
return this.type === type
}
}

this.type = type;
this.isUnknown = is_of_type('q');
this.isEmpty = is_of_type('0');
this.isFree = is_of_type('f');
this.isBomb = is_of_type('b');
this.isNumber = function () {
var eln = parseInt(this.type, 10);
return !isNaN(eln) && (eln !== 0)
};
}

function Position2D(row, col) {
this.row = +row;
this.col = +col;
this.toString = function () { return '(' + row + ', ' + col + ')' };
}
23 changes: 23 additions & 0 deletions generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function generate (width, height, mines, seed) {
if (mines > elems || width <= 0 || height <= 0) {
return null;
}
var elems = width * height;

var coeffs_arr = [elems - mines];
for (var i = 1; i <= mines; ++i) {
coeffs_arr.push(coeffs_arr[i-1] * (elems - mines + i));
}

var field = create_matrix(height, width, function() { return false; });

var rest = create_map(elems, function(i) { return i; });
for (var i = mines - 1; i >= 0; --i) {
var r_idx = Math.floor(seed / coeffs_arr[i]) % rest.length;
var idx = rest.splice(r_idx, 1)[0];
field[Math.floor(idx / width)][idx % width] = true;
seed %= coeffs_arr[i];
}

return field;
}
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
<meta charset="UTF-8" />
<title>Antisweep</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="util.js"></script>
<script src="classes.js"></script>
<script src="solver.js"></script>
<script src="sweep.js" ></script>
<script src="generator.js" ></script>
</head>
<body onload="set_initial_page()">
<table id="main_table">
Expand Down
Loading