summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Zhao <ztuowen@gmail.com>2014-12-05 20:07:14 +0800
committerJoe Zhao <ztuowen@gmail.com>2014-12-05 20:07:14 +0800
commitc0825e62c58cd76d3f2b9c34637ee37a21de222a (patch)
tree08b83388fcce650eada0bc1a627c88df4aa999c1
parent0d3a0f0ca6c038ba931edbde87bd21db9397327b (diff)
downloadMahjong-c0825e62c58cd76d3f2b9c34637ee37a21de222a.tar.gz
Mahjong-c0825e62c58cd76d3f2b9c34637ee37a21de222a.tar.bz2
Mahjong-c0825e62c58cd76d3f2b9c34637ee37a21de222a.zip
Restructuring
-rw-r--r--aux/set/CardSet.java19
-rw-r--r--engine/Action.java13
-rw-r--r--player/PlayerActionHandler.java23
-rw-r--r--player/PlayerActionServer.java23
4 files changed, 52 insertions, 26 deletions
diff --git a/aux/set/CardSet.java b/aux/set/CardSet.java
index 56a998d..edea88a 100644
--- a/aux/set/CardSet.java
+++ b/aux/set/CardSet.java
@@ -72,6 +72,25 @@ public class CardSet {
{
//cnt=0;
int res=calTing(0,cardRem[0],0,0,mian);
+
+ // 7 pairs
+ int pairs=0;
+ for (int i:cardRem)
+ if (i>0) ++pairs;
+ res = Math.min(7 - pairs, res);
+
+ // Musou
+ int types=0;
+ pairs=0;
+ for (int i=0;i<cardTypeTotal;++i)
+ if (new Card(id2OrdLut[i]).is19())
+ {
+ ++types;
+ if (cardRem[i]>0)
+ ++pairs;
+ }
+ res = Math.min(14-(((pairs>0)?1:0)+types),res);
+
//System.out.println(cnt);
return res;
}
diff --git a/engine/Action.java b/engine/Action.java
index f544909..3009fa0 100644
--- a/engine/Action.java
+++ b/engine/Action.java
@@ -8,14 +8,27 @@ public class Action {
// Requirement: printable,parseable,coverage
// Coverage: System,player
public enum Type {System,Player};
+ // System info merely reflect system state
+ // Player info pertaining to players;
+ public enum Place {Info,East,South,West,North};
public enum Act {Info,CardDraw,CardPut,Aside};
Type type;
+ Act act;
+ Place place;
+ String message;
public Type getType() {
return type;
}
+ public Action(Type type,Place place,Act act,String message)
+ {
+ this.type = type;
+ this.place = place;
+ this.act = act;
+ this.message = message;
+ }
public Action(String str)
{
}
diff --git a/player/PlayerActionHandler.java b/player/PlayerActionHandler.java
index 05a042c..26ba7e3 100644
--- a/player/PlayerActionHandler.java
+++ b/player/PlayerActionHandler.java
@@ -6,24 +6,7 @@ import mahjong.engine.Action;
/**
* Created by joe on 12/4/14.
*/
-public abstract class PlayerActionHandler {
- public Hand hand=new Hand();
- int score;
-
- protected String name;
-
- public String getName() {
- return name;
- }
-
- public abstract Action stateAlert(Action action);
- public abstract void stateUpdate(Action action);
-
- public void setScore(int score) {
- this.score = score;
- }
-
- public int getScore() {
- return score;
- }
+public interface PlayerActionHandler {
+ public abstract Action stateAlert(Action action); // Player action required or not, state will not change
+ public abstract void stateUpdate(Action action); // Player action taken, changing state.
}
diff --git a/player/PlayerActionServer.java b/player/PlayerActionServer.java
index 49fcef4..09d2417 100644
--- a/player/PlayerActionServer.java
+++ b/player/PlayerActionServer.java
@@ -6,21 +6,32 @@ import mahjong.engine.Action;
/**
* Created by joe on 12/4/14.
*/
-public abstract class PlayerActionServer {
- public Hand hand=new Hand();
+
+// TODO Hard to manage relations
+public class PlayerActionServer implements PlayerActionHandler {
+ Hand hand=new Hand();
int score;
protected String name;
+ PlayerActionHandler player;
+
+ PlayerActionServer(PlayerActionHandler player)
+ {
+ this.player=player;
+ }
+
public String getName() {
return name;
}
- public abstract Action stateAlert(Action action);
- public abstract void stateUpdate(Action action);
+ public Action stateAlert(Action action)
+ {
+ return null;
+ }
- public void setScore(int score) {
- this.score = score;
+ public void stateUpdate(Action action)
+ {
}
public int getScore() {