001 ///////////////////////////////////////////////////////////////////////////////
002 // Copyright (c) 2006, Frank S. Nestel, All Rights Reserved.
003 //
004 // This library is free software; you can redistribute it and/or
005 // modify it under the terms of the GNU Lesser General Public
006 // License as published by the Free Software Foundation; either
007 // version 2.1 of the License, or (at your option) any later version.
008 //
009 // This library is distributed in the hope that it will be useful,
010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012 // GNU General Public License for more details.
013 //
014 // You should have received a copy of the GNU Lesser General Public
015 // License along with this program; if not, write to the Free Software
016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017 ///////////////////////////////////////////////////////////////////////////////
018
019 package de.spieleck.app.turn.scoring;
020
021 import de.spieleck.app.turn.PlayerGameScore;
022 import de.spieleck.app.turn.PlayerScore;
023
024 /**
025 * A ScoringMode for the game Mü.
026 * <br />
027 * During a match of the card game, every player obtains
028 * a individual score which is used as his outcome. The
029 * inter table normalization only consists of making the
030 * sum of scores on a table being zero summed.
031 *
032 * <p><a href="$URL: https://svn.sourceforge.net/svnroot/jtourney/src/de/spieleck/app/turn/scoring/Mue.java $">$URL: https://svn.sourceforge.net/svnroot/jtourney/src/de/spieleck/app/turn/scoring/Mue.java $</a></p>
033 *
034 * @author Frank S. Nestel
035 * @author $Author: nestefan $
036 * @version $Revision: 2 $ $Date: 2006-03-20 14:33:27 +0100 (Mo, 20 Mrz 2006) $ $Author: nestefan $
037 */
038 public class Mue
039 extends BaseScoring
040 {
041 public PlayerGameScore parseRawScore(String line)
042 {
043 return new MueScore(Double.parseDouble(line));
044 }
045
046 public PlayerGameScore[] adjustScore(PlayerGameScore[] pgs)
047 {
048 double h = 0.0;
049 for(int i = 0; i < pgs.length; i++)
050 h += ((MueScore)pgs[i]).d;
051 h /= pgs.length;
052 MueScore[] res = new MueScore[pgs.length];
053 for(int i = 0; i < pgs.length; i++)
054 res[i] = new MueScore(((MueScore)pgs[i]).d - h);
055 return res;
056 }
057
058 public PlayerGameScore zeroScore()
059 {
060 return new MueScore(0);
061 }
062
063 public PlayerScore addPlayers(PlayerScore ps, PlayerScore pgs)
064 {
065 return new MueScore(((MueScore)ps).d + ((MueScore)pgs).d);
066 }
067
068 public static class MueScore
069 implements PlayerGameScore, PlayerScore
070 {
071 private double d;
072
073 public MueScore(double d)
074 {
075 this.d = d;
076 }
077
078 public int compareTo(Object o)
079 {
080 if ( ! ( o instanceof MueScore ) )
081 return -1;
082 double delta = this.d - ((MueScore)o).d;
083 if ( delta > 0.0 )
084 return +1;
085 else if ( delta < 0.0 )
086 return -1;
087 return 0;
088 }
089
090 public String toString()
091 {
092 return Double.toString(d);
093 }
094 }
095
096 public String toString()
097 {
098 return "Mue";
099 }
100 }