Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Conanbatt
authored and
Conanbatt
committed
Nov 30, 2012
1 parent
baf9f9d
commit 0297734
Showing
3 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Pattern recognition</title> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
<link rel="stylesheet" href="qunit/qunit.css" type="text/css" media="screen"> | ||
<script type="text/javascript" src="sgf.js"></script> | ||
<script type="text/javascript" src="pattern_recognition.js"></script> | ||
<script type="text/javascript" src="qunit/qunit.js"></script> | ||
<script type="text/javascript" src="pattern_recognition_test.js"></script> | ||
</head> | ||
<body> | ||
<h1 id="qunit-header">Sgf Parser</h1> | ||
<h2 id="qunit-banner"></h2> | ||
<div id="qunit-testrunner-toolbar"></div> | ||
<h2 id="qunit-userAgent"></h2> | ||
<ol id="qunit-tests"></ol> | ||
<div id="qunit-fixture">test markup</div> | ||
|
||
</body> | ||
</html> | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
function PatternRecognizer(sgf){ | ||
|
||
this.sgf = sgf; | ||
|
||
|
||
function count(pattern_name){ | ||
|
||
var pattern = PatternRecognizer.patterns[pattern_name]; | ||
if (!pattern){ | ||
throw new Error("Pattern is not in the library! Add it"); | ||
} | ||
//Do pattern matching magic based on the sgf | ||
} | ||
|
||
this.count = count; | ||
} | ||
|
||
|
||
function Pattern(name, description, pattern){ | ||
if (!name || !description || !pattern){ | ||
throw new Error("invalid arguments"); | ||
} | ||
this.name = name; | ||
this.description = description; | ||
this.pattern = pattern; | ||
|
||
return this; | ||
} | ||
|
||
PatternRecognizer.patterns = { | ||
"empty triangle" : new Pattern("empty triangle", "empty triangles are bad", ["BB","BE"]), | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
var basic_pattern_file = "(;GM[1]FF[4]CA[UTF-8]AP[CGoban:3]ST[2]" + | ||
";U[Japanese]SZ[19]KM[0.00]"+ | ||
";W[White]PB[Black]"+ | ||
";B[dc]"+ | ||
";W[pc]"+ | ||
";B[cc]"+ | ||
";W[od]"+ | ||
";B[cd]"+ | ||
";W[pe]"+ | ||
";B[cp]"+ | ||
";W[qd]"+ | ||
";B[eq]"+ | ||
";W[pp]"+ | ||
";B[qn]"+ | ||
";W[qo]"+ | ||
";B[pn]"+ | ||
";W[np])"; | ||
|
||
var recognizer; | ||
|
||
module("Pattern recognition basic", { | ||
setup: function() { | ||
|
||
basic_pattern_sgf = new SGFParser(basic_pattern_file); | ||
recognizer = new PatternRecognizer(basic_pattern_sgf); | ||
}, | ||
teardown: function() { | ||
} | ||
}); | ||
|
||
test("Should be able to recognize shapes", function(){ | ||
|
||
equal(recognizer.count("empty triangle"), 1); | ||
equal(recognizer.count("ponnuki"), 1); | ||
equal(recognizer.count("kick"), 1); | ||
equal(recognizer.count("shimari"), 1); | ||
|
||
equal(recognizer.count("broken ikken tobi"), 1); | ||
equal(recognizer.count("broken keima"), 1); | ||
equal(recognizer.count("broken hazama tobi"), 1); | ||
}); | ||
|