Changed TrickCardGameUtil to use more sensible round-the-table ordering. Changed TeamGameConfig to return the actual indices of the team members, so that teammates need not have consecutive indices.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3496 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Andrzej Kapolka
2005-04-16 02:00:57 +00:00
parent 90e3065751
commit 4266c72977
3 changed files with 21 additions and 33 deletions
@@ -28,14 +28,14 @@ import com.threerings.parlor.card.data.CardCodes;
*/
public interface TrickCardCodes extends CardCodes
{
/** For four-player games, the top (opposite) player. */
public static final int TOP = 0;
/** For four-player games, the bottom (own) player. */
public static final int BOTTOM = 1;
public static final int BOTTOM = 0;
/** For four-player games, the player on the left. */
public static final int LEFT = 2;
public static final int LEFT = 1;
/** For four-player games, the top (opposite) player. */
public static final int TOP = 2;
/** For four-player games, the player on the right. */
public static final int RIGHT = 3;
@@ -40,7 +40,7 @@ public class TrickCardGameUtil
*/
public static int getTeamIndex (int pidx)
{
return pidx / 2;
return pidx & 1;
}
/**
@@ -51,7 +51,7 @@ public class TrickCardGameUtil
*/
public static int getOtherTeamIndex (int tidx)
{
return 1 - tidx;
return tidx ^ 1;
}
/**
@@ -60,7 +60,7 @@ public class TrickCardGameUtil
*/
public static int getPartnerIndex (int pidx)
{
return pidx ^ 1;
return pidx ^ 2;
}
/**
@@ -72,7 +72,7 @@ public class TrickCardGameUtil
*/
public static int getTeamMemberIndex (int tidx, int midx)
{
return tidx * 2 + midx;
return (midx << 1) | tidx;
}
/**
@@ -82,15 +82,9 @@ public class TrickCardGameUtil
public static int getNextInClockwiseSequence (int pidx)
{
// 0
// 2 3
// 1
switch (pidx) {
case 0: return 3;
case 1: return 2;
case 2: return 0;
case 3: return 1;
default: return -1;
}
// 3 1
// 2
return (pidx + 1) & 3;
}
/**
@@ -103,7 +97,7 @@ public class TrickCardGameUtil
*/
public static int getRelativeLocation (int pidx1, int pidx2)
{
return RELATIVE_LOCATIONS[pidx1][pidx2];
return (pidx2 - pidx1) & 3;
}
/**
@@ -112,7 +106,7 @@ public class TrickCardGameUtil
*/
public static int getLeftIndex (int pidx)
{
return getNextInClockwiseSequence(pidx);
return (pidx + 1) & 3;
}
/**
@@ -121,7 +115,7 @@ public class TrickCardGameUtil
*/
public static int getRightIndex (int pidx)
{
return getNextInClockwiseSequence(pidx) ^ 1;
return (pidx + 3) & 3;
}
/**
@@ -130,7 +124,7 @@ public class TrickCardGameUtil
*/
public static int getOppositeIndex (int pidx)
{
return pidx ^ 1;
return pidx ^ 2;
}
/**
@@ -198,9 +192,4 @@ public class TrickCardGameUtil
}
return highest;
}
/** The locations of the other players for each player index. */
protected static final int[][] RELATIVE_LOCATIONS = {
{BOTTOM, TOP, RIGHT, LEFT}, {TOP, BOTTOM, LEFT, RIGHT},
{LEFT, RIGHT, BOTTOM, TOP}, {RIGHT, LEFT, TOP, BOTTOM} };
}
@@ -24,15 +24,14 @@ package com.threerings.parlor.game.data;
import com.threerings.parlor.data.TableConfig;
/**
* Provides additional information for games with fixed teams.
* Provides additional information for games with teams.
*/
public interface TeamGameConfig extends TableConfig
{
/**
* Returns the number of players on the first n-1 of n teams. For
* instance, a game with four players in two partnerships would
* return { 2 }, indicating that players 0 and 1 are partnered
* against players 2 and 3.
* Returns the members of each team. For instance, a game with three
* players in two teams--players 0 and 2 versus player 1--would return
* { {0, 2}, {1} }.
*/
public int[] getTeamCounts ();
public int[][] getTeamMemberIndices();
}