private int winnerByManhattan() { int score0 = 0; int score1 = 0; for (int y = 0; y < IField.cFieldHeight; y++) { for (int x = 0; x < IField.cFieldWidth; x++) { IGhost g = getGhost(x, y); if (g == null) { continue; } if (g.getType() == GhostType.Good) { int team = g.getTeamId(); if (team == 0) { score0 += Math.Min(TPoint.manhattan(IField.GetGoalPositions(0)[0], x, y), TPoint.manhattan(IField.GetGoalPositions(0)[1], x, y)); } else { score0 += Math.Min(TPoint.manhattan(IField.GetGoalPositions(1)[0], x, y), TPoint.manhattan(IField.GetGoalPositions(1)[1], x, y)); } } } } return(score0 < score1 ? 0 : score1 < score0 ? 1 : 2); }
/** * 勝敗が決した場合は勝ったチームのidを返す * そうでない場合は-1を返す */ public int move(int teamId, TPoint from, TPoint to) { Debug.Assert(TPoint.manhattan(from, to) == 1); Ghost tar = getGhostImpl(from); Debug.Assert(tar != null); Debug.Assert(tar.getTeamId() == teamId); Debug.Assert(isInField(to) || (tar.getType() == GhostType.Good && isInGoal(teamId, to))); Ghost next = getGhostImpl(to); if (next != null) { Debug.Assert(next.getTeamId() != teamId); if (next.isEvil()) { fragedEvilNum[teamId]++; } else { fragedGoodNum[teamId]++; } } setGhost(from, null); setGhost(to, tar); if (getFraggedEvilNum(teamId) >= cTeamGhostNum / 2) { //悪ゴーストを全部取った。負け mDetail = CauseOfResult.FragAllEvil; return(1 - teamId); } else if (getFraggedGoodNum(teamId) >= cTeamGhostNum / 2) { //善ゴーストを全部取った。勝ち。 mDetail = CauseOfResult.FragAllGood; return(teamId); } //相手側の善ゴーストがゴールしてたら相手の勝ち foreach (TPoint p in IField.GetGoalPositions(1 - teamId)) { var g = getGhost(p); if (g == null) { continue; } if (g.getType() == GhostType.Good && g.getTeamId() == 1 - teamId) { mDetail = CauseOfResult.Goal; return(1 - teamId); } } //まだ決着がついていない return(-1); }
static private void initManhattanScore() { if (sManhattanScore != null) { return; } sManhattanScore = new int[2, (IField.cFieldHeight + 2) * (IField.cFieldWidth + 2)]; for (int t = 0; t < 2; t++) { for (int y = 0; y < IField.cFieldHeight; y++) { for (int x = 0; x < IField.cFieldWidth; x++) { sManhattanScore[t, Index(x, y)] = Math.Min( TPoint.manhattan(IField.GetGoalPositions(t)[0], x, y), TPoint.manhattan(IField.GetGoalPositions(t)[1], x, y)); } } } }
virtual public bool canMove(int teamId, TPoint from, TPoint to) { if (TPoint.manhattan(from, to) != 1) { return(false); } IGhost tar = getGhost(from); if (tar == null || tar.getTeamId() != teamId) { return(false); } /* * if (isInGoal(teamId, to)) * { * if (tar.getType() == GhostType.Good) * { * return true; * } * else * { * return false; * } * } */ if (!isInField(to)) { return(false); } IGhost next = getGhost(to); if (next != null && next.getTeamId() == teamId) { return(false); } return(true); }