The2Tigers(二虎棋)
Example:
Code snippet
Supplmentary interpretation
Thinking...
Fuzzy logic, whenever is safty,wherever is dangerous?
Thinking...
Fuzzy logic, whenever is safty,wherever is dangerous?
First off,three key words:
1.adjacent;
2.opposite;
3.hypotenuse;
Next,how to draw triangle using Degrafa?
<Polygon fill="{upFill}">
<data>0,70 40,0 80,70</data>
</Polygon>
rotate 180 degree?
<Polygon fill="{upFill}">
<transform>
<RotateTransform angle="180" centerX="40" centerY="35"/>
</transform>
<data>0,70 40,0 80,70</data>
</Polygon>
Next,how to determine the 3 directs? Using the graph data struct to finding simple path existed from adjacent to opposite and
from adjacent to hypotenuse and from opposite to hypotenuse.the simple path finding searcher function as follows:
1.Dijkstra:
package jp.dip.hael.gameai.graph.searcher
{
import jp.dip.hael.gameai.graph.GraphEx;
import jp.dip.hael.gameai.graph.Edge;
import jp.dip.hael.gameai.graph.WeightedEdge;
import jp.dip.hael.gameai.util.PriorityQueueDsc;
public class Dijkstra extends Searcher
{
public function Dijkstra(graph:GraphEx)
{
super(graph);
}
public override function search(src:int, dst:int):Boolean
{
var pq:PriorityQueueDsc = new PriorityQueueDsc();
pq.insert(new Edge(src, src), 0);
var route:Array /* of int */ = new Array(graphRef_.size);
var weight:Array /* of int */ = new Array(graphRef_.size);
while(pq.length > 0){
var next:Edge = pq.popObj() as Edge;
route[next.dst] = next.src;
if(next.dst == dst){
src_ = src;
dst_ = dst;
route_ = route;
found_ = true;
return true;
}
var dsts:Array = graphRef_.edge(next.dst);
for each(var e:WeightedEdge in dsts){
if(route[e.dst] === undefined){
var w:int = (weight[next]>>0) + e.weight;
weight[e.dst] = w;
pq.insert(e, w);
}
}
}
return false;
}
}
}
2.Bread-first traversal:
override public function search(src:int, dst:int):Boolean
{
var queue:Array /* of Edge */ = [];
queue.push(new Edge(src, src));
var visited:Array /* of Boolean */ = new Array(graphRef_.size);
visited[src] = true;
var route:Array /* of int */ = new Array(graphRef_.size);
while(queue.length > 0){
var next:Edge = queue.shift();
route[next.dst] = next.src;
if(next.dst == dst){
src_ = src;
dst_ = dst;
route_ = route;
found_ = true;
return true;
}
var dsts:Array = graphRef_.edge(next.dst);
for each(var e:Edge in dsts){
if(!visited[e.dst]){
queue.push(e);
visited[e.dst] = true;
}
}
}
return false;
}
3.Depth-first traversal:
override public function search(src:int, dst:int) : Boolean
{
var queue:Array /* of Edge */ = [];
queue.push(new Edge(src, src));
var visited:Array /* of Boolean */ = new Array(graphRef_.size);
visited[src] = true;
var route:Array /* of int */ = new Array(graphRef_.size);
while(queue.length > 0){
var next:Edge = queue.pop();
route[next.dst] = next.src;
if(next.dst == dst){
src_ = src;
dst_ = dst;
route_ = route;
found_ = true;
return true;
}
var dsts:Array = graphRef_.edge(next.dst);
for each(var e:Edge in dsts){
if(!visited[e.dst]){
queue.push(e);
visited[e.dst] = true;
}
}
}
return false;
}
...
This page is wiki editable click here to edit this page.
<degrafa:Surface>
<degrafa:strokes>
<paint:SolidStroke id="whiteStroke"
color="#FFF"
weight="1"
alpha=".5"/>
</degrafa:strokes>
<degrafa:GeometryGroup>
<geometry:RegularRectangle id="hRegularRect" width="150" height="450" x="{150+PADDING}" y="{PADDING}" stroke="{whiteStroke}"/>
<geometry:RegularRectangle id="vRegularRect" width="450" height="150" y="{150+PADDING}" x="{PADDING}" stroke="{whiteStroke}"/>
</degrafa:GeometryGroup>
</degrafa:Surface>
How to find all simple paths which length limited by 5,such as a-b-c-d-e?
override public function searchAll(src:int, dst:int, visited:ArrayCollection) : void
{
var nodes:Array = new Array();
if(!(graphRef_.edge(src) is Array))
{
return;
}
for(var i:int=0;i<graphRef_.edge(src).length;i++)
{
nodes.push( (graphRef_.edge(src)[i] as WeightedEdge).dst );
}
//trace("nodes:",nodes);
for(var node:* in nodes)
{
//trace("~node:",node,"nodes[node]",nodes[node]);
if(visited.contains(nodes[node]))
{
continue;
}
if(int(nodes[node])==dst)
{
visited.addItem(nodes[node]);
//restore this path.
saveToAllSimplePaths(visited);
visited.removeItemAt(visited.length-1);
break;
}
}
// in breadth-first, recursion needs to come after visiting adjacent nodes
for(var node2:* in nodes)
{
//trace("~~node:",node,"nodes[node]",nodes[node]);
if(visited.contains(nodes[node2])||int(nodes[node2])==dst)
{
continue;
}
visited.addItem(nodes[node2]);
searchAll(nodes[node2],dst,visited);
visited.removeItemAt(visited.length-1);
}
}
This page is wiki editable click here to edit this page.
First off,how to make chess board using Degrafa,so easy as follows:
<degrafa:Surface>
<degrafa:strokes>
<degrafa:SolidStroke id="whiteStroke"
color="#FFF"
weight="1"
alpha=".5"/>
</degrafa:strokes>
<degrafa:GeometryGroup>
<degrafa:VerticalLineRepeater
id="vlRepeater"
count="4"
stroke="{whiteStroke}"
x="{PADDING}"
y="{PADDING}"
y1="{height-PADDING}"
offsetX="0"
offsetY="0"
moveOffsetX="120"
moveOffsetY="0"/>
<degrafa:HorizontalLineRepeater
id="hlRepeater"
count="4"
stroke="{whiteStroke}"
x="{PADDING}"
y="{PADDING}"
x1="{width-PADDING}"
offsetX="0"
offsetY="0"
moveOffsetX="0"
moveOffsetY="120"/>
</degrafa:GeometryGroup>
</degrafa:Surface>
Next,search:
...
Next,evaluation:
...
Next,knowledge:
...
Next,learning:
...