Topic: Java Mah Jong

Offline Tiwaking!

  • Hero Member
  • Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!
  • Posts: 12,584
Having recently acquired a Mah Jong set I have been playing Mah Jong recently and found scoring hands to be quite a chore, especially if you are bad at math like myself.

Here is a simple program that will score hands in Mah Jong. It wont score special hands properly though since they are limit/half limit hands anyways.
Spoiler :
edit: I have changed the code to add action listeners to all the boxes and combo boxes. Having to press "calculate score" all the time is really annoying on a laptop
Code: [Select]
//Fri Dec 14 21:21:25 NZDT 2012
//Sat Dec 15 08:12:52 NZDT 2012 - Added action listener to everything
/*Below is the input used to generate this code
JPanel panel
*/
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.util.Scanner;
import java.util.ArrayList;
import java.text.NumberFormat;
import javax.swing.border.Border;
import java.util.*;
import java.io.*;
public class MahJongScorePanel extends JPanel implements ActionListener,KeyListener{
protected final String[]types={"Suit","Honour"};
protected final JCheckBox[]boxes=new JCheckBox[4];
protected final JFormattedTextField txtScore=new JFormattedTextField(NumberFormat.getIntegerInstance());
protected final JButton btnScore=new JButton("Calculate Score");
protected final Border blackline=BorderFactory.createLineBorder(Color.black);
protected final JFormattedTextField txtMisc=new JFormattedTextField(NumberFormat.getIntegerInstance());
protected final String[]sets={"Pung","Kong","Run"};
protected final JPanel[]setPanels=new JPanel[4];
protected final JComboBox[]boxSets=new JComboBox[setPanels.length];
protected final JComboBox[]boxTypes=new JComboBox[setPanels.length];
protected final JCheckBox boxMahJong=new JCheckBox("Mah Jong",true);
protected final JCheckBox boxPurity=new JCheckBox("Purity",false);
protected final JCheckBox boxOwnWind=new JCheckBox("Own Wind",false);
protected final JCheckBox boxRoundWind=new JCheckBox("Round Wind",false);
public static final String[]FILE_DIRECTORIES={"dot/","char/","bamb/","drag/","wind/"};
public static final LinkedHashSet<String>SPECIAL_TILES=new LinkedHashSet<String>(Arrays.asList(new String[]{
&quot;Plum&quot;,&quot;Orchid&quot;,&quot;Chrysanthemum&quot;,&quot;Bamboo&quot;,
&quot;Winter&quot;,&quot;Summer&quot;,&quot;Autumn&quot;,&quot;Spring&quot;}));
public MahJongScorePanel(){
setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
setSize(800,300);
for(int i=0;i<setPanels.length;i++){
JPanel panel=new JPanel();
panel.setLayout(new BoxLayout(panel,BoxLayout.X_AXIS));
panel.add(new JLabel(&quot;Set Type (3/4/Run)&quot;));
boxSets[i]=new JComboBox(sets);
boxSets[i].addActionListener(this);
panel.add(boxSets[i]);
boxes[i]=new JCheckBox(&quot;Concealed&quot;,false);
boxes[i].addActionListener(this);
boxes[i].setBorder(blackline);
panel.add(boxes[i]);
JLabel lbl=new JLabel(&quot;Suit or Honours&quot;);
lbl.setBorder(blackline);
panel.add(lbl);
boxTypes[i]=new JComboBox(types);
boxTypes[i].addActionListener(this);
panel.add(boxTypes[i]);
setPanels[i]=panel;
add(setPanels[i]);
}//4
JPanel pnl1=getPanel(true);
btnScore.addActionListener(this);
pnl1.add(btnScore);
pnl1.add(boxMahJong);
pnl1.add(new JLabel(&quot;Extra Points&quot;));
txtMisc.setValue(0);
boxPurity.addActionListener(this);
boxOwnWind.addActionListener(this);
boxRoundWind.addActionListener(this);
pnl1.add(txtMisc);
pnl1.add(boxPurity);
pnl1.add(boxOwnWind);
pnl1.add(boxRoundWind);
add(pnl1);
JPanel tmpPnl=new JPanel();
tmpPnl.setLayout(new BoxLayout(tmpPnl,BoxLayout.X_AXIS));
tmpPnl.add(new JLabel(&quot;Total Score:&quot;));
txtScore.setEditable(false);
tmpPnl.add(txtScore);
add(tmpPnl);
btnScore();
}//c
protected JPanel getPanel(boolean layout){
JPanel tmpPnl=new JPanel();
if(layout)tmpPnl.setLayout(new BoxLayout(tmpPnl,BoxLayout.X_AXIS));
else tmpPnl.setLayout(new BoxLayout(tmpPnl,BoxLayout.Y_AXIS));
return tmpPnl;
}
public void actionPerformed(ActionEvent ae){
// if(ae.getSource().equals(btnScore))btnScore();
btnScore();
}//actionPerformed
protected void btnScore(){
int score=0;
try{
score+=(Long)txtMisc.getValue();
}catch(Exception zerostart){}
int doubles=0;
if(boxMahJong.isSelected())score+=20;
for(int i=0;i<setPanels.length;i++){
int runScore=0;
if(boxSets[i].getSelectedIndex()==0)runScore=2;
if(boxSets[i].getSelectedIndex()==1)runScore=4;
if(boxTypes[i].getSelectedIndex()==1){
runScore*=2;
doubles++;
}//fi
if(boxes[i].isSelected())runScore*=2;
score+=runScore;
}//4 panels
if(boxPurity.isSelected())doubles++;
if(boxOwnWind.isSelected())doubles++;
if(boxRoundWind.isSelected())doubles++;
for(int i=0;i<doubles;i++){
score*=2;
}
txtScore.setValue(score);
}//btnScore
public void keyPressed(KeyEvent e){
int key=e.getKeyCode();
if(key == KeyEvent.VK_LEFT || key == KeyEvent.VK_NUMPAD4){

}//if you press left
if (key == KeyEvent.VK_RIGHT || key == KeyEvent.VK_NUMPAD6){

}//right

if(key == KeyEvent.VK_UP || key == KeyEvent.VK_NUMPAD8){

}//if you press up
if(key == KeyEvent.VK_DOWN || key == KeyEvent.VK_NUMPAD2){

}//down
}
public void keyReleased(KeyEvent e){

}
public void keyTyped(KeyEvent e){
if(e.getKeyChar() == 27){
System.exit(0);
}//esc
if(e.getKeyChar() == KeyEvent.VK_ENTER){

}
}//me keys
public static void main(String[]args){
JFrame frame=new JFrame(&quot;Mah Jong Score Panel by Tiwa Pene Fri Dec 14 22:32:42 NZDT 2012&quot;);
MahJongScorePanel scorepanel=new MahJongScorePanel();
frame.add(scorepanel);
frame.setSize(scorepanel.getSize());
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.setVisible(true);
}//main
}//class
The only actual java mah jong game (not that idiot solitaire version) I have found that is any good is this one:
edit: Whoops, messed up the link. Its missing a quotation mark
Mythosware Mah-Jong v1.0
------------------------

(C) Andrew Lawrenson 2010
http://www.mythosware.co.uk

Unfortunately the resolution to play it is something like 1400xsomething stupid which does nothing for the game.

p.s I have been working on Java Mah Jong since finding the previous one to be an unsuitable resolution, hence the screenshot from The Monopoly Thread which is a modified Mah Jong layout.
Last Edit: December 15, 2012, 08:15:07 am by Tiwaking!

Posted: December 14, 2012, 10:45:11 pm
I am now banned from GetSome

Offline Pyromanik

  • Hero Member
  • Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!
  • Posts: 28,834
I don't know what to do if not silly solitaire.

Reply #1 Posted: December 15, 2012, 12:11:31 am
Everyone needs more Bruce Campbell.

Offline oefox

  • Devoted Member
  • oefox has no influence.
  • Posts: 1,186
When you say hard scoring do you mean remembering all the possible special hands? Quite like the proper game but takes a while if there's only one manual. Programming the AI would be interesting.

Reply #2 Posted: December 15, 2012, 10:23:02 am
- badfox

Offline Tiwaking!

  • Hero Member
  • Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!
  • Posts: 12,584
Quote from: oefox;1511794
When you say hard scoring do you mean remembering all the possible special hands? Quite like the proper game but takes a while if there's only one manual. Programming the AI would be interesting.
Special Hands only score 500,1000,1500, or 2000 and half that when Fishing.

Depending on what rules you are using (British, American, Chinese, Japanese, Cantonese) the special hands are different.

Scoring special hands is easy, because they only have one way of appearing which gives you a Map of possible tile combinations. e.g

Nothing Connects has a set arrangement of tiles as does Great Jade Hand.

These hands get scored to the 'limit' (usually 1000) or half limit (500). When you are playing for money, it is usually no limit. If you are playing for lollies, then it is DEFINITELY no limit! Usually: 1 lolly = 10 points so a limit hand means most other players will probably have to pay you 100 lollies. YAY DIABETES!


The scoring is just for a 'normal' hand, which is annoying to do. Oh! Since we have Pyromanik here who does know how to play, I might as well post up the rules :D


Mah Jong: Easy to play
If you've played Gin Rummy, Rummy, Five Hundred, or Bridge then you most certainly know how to play Mah Jong, because it is the game the Card Games originated from.


Mah Jong is pretty easy to learn how to play. A Mah Jong set consists of 136 tiles, but most sets have 144 tiles (4 seasons, 4 flowers). In Mah Jong there are three 'suits' of tiles

Bamboo
Characters
Circles (Actually 'Coins' in Cantonese/Chinese)

Each of these tiles are numbered 1 to 9. There are four of every tile.

There are also two 'honour' type tiles:
Winds: East, West, North, South
Dragons: Red, Green, White (usually a blank tile)

There are four of each of these tiles too.
Mah Jong: Players Hands
In Mah Jong you need four players for a proper game.
Each Player has a hand of thirteen (13) tiles. To win you have to declare Woo/Mah Jong by drawing a winning tile or picking up another players discarded tile.

The simplest way to go Mah Jong is as follows:

four sets of three tiles (either 3 of a kind OR a run (1,2,3/2,3,4/5,6,7 etc)) (twelve (12) tiles in total)
A pair (making fourteen (14) tiles)

There are 'special' hands which I will ignore for now.
Mah Jong: How rounds work
At the start of the game each player is assigned a Wind (North, South, East, West) which follows naturally from the Never Eat Sour Watermelons order.
Depending on what rules you are playing, there is also a 'Prevailing Wind' which I will explain later.

East Wind is always the Dealer (Also Prevailing Wind at the beginning of a game). East Wind draws first. East Wind always gets PAID DOUBLE, but also LOSES DOUBLE if they dont go Mah Jong.


Play goes in Order (East, South. West, North). Each player draws a tile to make a hand of 14 tiles, but then must discard a tile.
All discarded tiles go in the center of the table.
ANY PLAYER may declare "PUNG!"(3 of a kind), "KONG!"(four of a kind),"CHOW!"(a run), or Mah Jong and pick up the discarded tile.
Then THAT PLAYER must reveal their set/run and discard a tile (unless they went Mah Jong)
When sets/runs are Revealed, they are placed FACE UP in front of the player to show the other players what that player has.

If a player picks up a discarded tile, then play continues from that player. In intense Mah Jong games, players can miss several goes and not even get the opportunity to go Mah Jong.

The order of precedence for tiles works as follows (highest priority to lowest): Mah Jong, Kong, Pung, Chow. IF there is a tie (two people go Mah Jong) then the player who is next in line of turn gets precedence (Chinese Rules)

SPECIAL - If a player has a Four of a kind then they must draw an extra tile from the "Dead Wall", but if not playing with a Dead Wall (simplified rules) then simply take a tile from the END OF THE WALL, not from the normal draw end.
Mah Jong: Scoring
This is where my little program comes in. Scoring is very easy, but can be time consuming when a big hand is played.
These are the 'simplified' rules for scoring, proper Cantonese/Gambling rules can be quite complex because once money is involved, all morality goes out the window.

Pung (3 of a kind): 2 points
Kong (4 of a kind): 4 points
Chow (run): 0 points

Revealed: normal
Concealed: points*2 (Concealed is when you make a set without having picked up a discarded tile/forced to reveal)

Honours Tiles (Dragons or Winds): points*2 (+1 double)

Going Mah Jong +20
(Simplified rules do not use the special points for 1/9 of suits which are worth double)
For example: A pung of two (2) of bamboo would net you 2 points if revealed, 4 points if concealed, but a pung of Green Dragons would get you 4 points revealed and 8 points of concealed (plus a double which I will explain later)

Mah Jong: Scoring Doubles

This is where the fun begins. In special cases, your score can be doubled. As I mentioned before, for each pung/kong of honour tiles you get to double your total overall score.
Other ways are:

Pung/Kong of own Wind: +1 double
Pung/Kong of prevailing Wind: +1 double
Purity (One suit only + Dragons/Winds): +1 double
Purity (One suit, no winds, no dragons): +2 doubles (or +3 doubles, I forget)


Dont forget that EAST WIN PAYS DOUBLE/WINS DOUBLE
Spoiler :

Mah Jong: Limit Hands
As you may realise, some hands will have an absolute mammoth score. Anything over 128 points is 'unusual', anything over 200 points is a very good hand.

Anything over 1000 points means everyone else goes home broke.
e.g Hand consists of 4*East Wind concealed + 3*Red Dragon Revealed+3*Green Dragon Revealed + 4*West Wind revealed + White Dragon Pair
8 points (+1 double) + 4 points (+1 double) + 4 points (+1 double) + 16 points (+1 double) + 20 Mah Jong
32 + 20 = 52 points
52*2*2*2*2 = 3328 (which is well above the limit)

Oh yeah, I forgot: East Wind means everyone pays you double.

People would never play with you again

Mah Jong: Scoring What is so hard about that?

Well: When you go Mah Jong, everyone pays the 'winner'/Mah Jonger (who may not actually be the 'winner' at all)

Each player scores their hand and they PAY THE DIFFERENCE BETWEEN THEIR HAND AND THE WINNERS HAND
This means a person can have a better hand than the person who won, which depending on the rules means that:

a) The Mah Jong player pays that person the difference in their scores (in a serious game)
b) The player does not have to pay the Mah Jong player anything (usual rule)


This also means that a person who has nothing in their hand at the end pays the most.
This also means that being EAST WIND (the Dealer) can be a blessing or a curse (much like "Clubs Compulsary" in Euchre).

Mah Jong: Conclusion

I've found that people who hate card games LOVE Mah Jong because the Tiles are more tactile and its alot more interactive ('stealing' peoples turns or even better: The tiles they need) plus, if you play with Cantonese people, the smack talk never stops.
(spoiler contains picture of Java Game thing I am making)
Spoiler :



Reply #3 Posted: December 15, 2012, 12:41:15 pm
I am now banned from GetSome

Offline oefox

  • Devoted Member
  • oefox has no influence.
  • Posts: 1,186
jimeny crickets, is that win2000?

Reply #4 Posted: December 15, 2012, 06:01:52 pm
- badfox

Offline Tiwaking!

  • Hero Member
  • Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!
  • Posts: 12,584
Here is a screenshot of what I have so far. You have to manually arrange your hand, which is fine because all the auto arrange hand versions have been rubbish. Exactly how you arrange your hand is an important part of the game and auto arrange tends to break that strategy slightly.

All the Draw Tile logic is handled by the players hands (if you draw a Flower/Season tile, then it is placed into their Special Tiles/Revealed Tiles section)
What needs to be done now is the Pung/Kong/Chow from drawn tiles. Also need Mah Jong calculation, which is not actually necessary because in Real Mah Jong you can go out even when not fishing by drawing tiles from the dead wall (e.g Kong + Chow + Pair). Still need a 'Mah Jong' calculator though to make sure the player hasnt cheated. In Mah Jong, you lose 20 points for calling a false Mah Jong or you pay everyone, whichever is worse.

Quote from: oefox;1511828
jimeny crickets, is that win2000?

No it is Windows 95

Reply #5 Posted: December 15, 2012, 07:03:20 pm
I am now banned from GetSome

Offline Pyromanik

  • Hero Member
  • Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!
  • Posts: 28,834
Windows 95 didn't have a gradient title bar or 32bit icons.

Reply #6 Posted: December 15, 2012, 08:03:57 pm
Everyone needs more Bruce Campbell.

Offline Demandred

  • Game Server Admin
  • Demandred has no influence.
  • Posts: 1,379
good shit - its is almost impossible to find an actual mah-jong game and not the crap that is passed off for it. I have an average version on my iphone but was always a fun game

**You must spread some Reputation around before giving it to Tiwaking! again.**

Reply #7 Posted: December 16, 2012, 09:25:24 pm

Offline Tiwaking!

  • Hero Member
  • Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!
  • Posts: 12,584
Quote from: oefox;1511794
When you say hard scoring do you mean remembering all the possible special hands? Quite like the proper game but takes a while if there's only one manual. Programming the AI would be interesting.

The AI for MahJong games is pretty poor with the exception of the Japanese scoring versions of MahJong (because the Japanese version is weird).

Generally: The AI goes for the highest possible scoring hand which makes it very easy to Stone Wall (never discard the tiles it wants ending in a Dead Hand), this is especially true in the Traditional Mah Jong setup (with a Dead Tile wall)


If you were to make an AI I guess you could have it calculate a good possible hand from what it starts with and then have it aim for that. It is a very narrow approach, but usable.
Quote from: Demandred;1511916
good shit - its is almost impossible to find an actual mah-jong game and not the crap that is passed off for it. I have an average version on my iphone but was always a fun game

**You must spread some Reputation around before giving it to Tiwaking! again.**

I am taking a break to go play actual Mah Jong today. Attached to this is a zip file containing a Java Jar file.

Inside the jar file are all the BlueJ project files, directories with images, and Source Files.

It has not been setup to be a proper executable jar file (using url="getCodeBase(),"img/"). To run it you will have to extract the image directorys from the jar file.


If you did not understand the previous sentence: Get out of my thread. You have no business being here.


What is missing is the Win Condition (you cannot go Mah Jong) and any kind of help files. You can also claim any tile even if it doesnt make a meld/set/pung/kong/chow.

edit: I'll finish it properly later. It is abit hard to find motivation to make something when you can just pull out a set and play it in real life with other people.
Last Edit: December 17, 2012, 12:08:24 pm by Tiwaking!

Reply #8 Posted: December 17, 2012, 12:06:35 pm
I am now banned from GetSome

Offline Tiwaking!

  • Hero Member
  • Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!
  • Posts: 12,584
Just getting the pictures to show up took awhile.
Merry Christmas
http://tiwaking.hostzi.com/mahjong/mahjong.html

How To Play:
Tiles are drawn and placed at Bottom or Right hand side of hand
SO - Sorts your hand
XX - Declines a discard

4 Seasons and 4 Flowers

Discards can be claimed for Chow, Pung, Kong, or Mah Jong, but the Mah Jong does not work in some instances

When a panel turns Yellow it means it is fishing for Mah Jong
Green Panel means it is that players turn


Things that do not work:
Mah Jong when Pung
Chow Check for Fishing (I Think)
There is no Dead Wall
No scoring (though I've already made a program that scores)
No 'Full Game'
No Prevailing Wind
No AI

Reply #9 Posted: December 25, 2012, 09:07:50 am
I am now banned from GetSome

Offline Tiwaking!

  • Hero Member
  • Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!
  • Posts: 12,584
Quote from: Tiwaking!;1511778
The only actual java mah jong game (not that idiot solitaire version) I have found that is any good is this one:
Mythosware Mah-Jong v1.0
------------------------

(C) Andrew Lawrenson 2010
http://www.mythosware.co.uk

Unfortunately the resolution to play it is something like 1400xsomething stupid which does nothing for the game.

p.s I have been working on Java Mah Jong since finding the previous one to be an unsuitable resolution, hence the screenshot from The Monopoly Thread which is a modified Mah Jong layout.

After playing the mythosware Mah Jong all night I feel quite chuffed about the Mah Jong I made.

I stumbled across several game breaking bugs in the Mythos version, INCLUDING the ones I managed to fix in my version (notably "Fishing with a broken chow"), plus a few game critical ones (Multiple calls for Mah Jong from one tile crashes the game). Also: The scoring in the Mythos version is weird. Normally your score is doubled for EACH pung or Kong of Dragons/Winds, but this game makes it doubled once for any dragon/wind meld. It also gives very few doubles for anything else (no chows = double, All One Suit + Winds/Dragons = Double)


This makes Dragon/Wind tiles the most powerful tiles in the game, which means the computer very, very, rarely throws them away. Which means the game devolves into dead hand after dead hand with incredibly low (below 200) scores being the norm.

Reply #10 Posted: December 30, 2012, 10:50:52 am
I am now banned from GetSome

Offline Tiwaking!

  • Hero Member
  • Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!
  • Posts: 12,584
Quote from: Tiwaking!;1513034
After playing the mythosware Mah Jong all night I feel quite chuffed about the Mah Jong I made.

After playing the exceptionally unintuitive JMhing I am beginning to wonder if all the people who make the free to play MahJong games actually know what they are doing.


JMhing is a java based version of the (surprisingly rare) card game Mhing (http://boardgamegeek.com/boardgame/1452/mhing). Essentially Mhing is the very essence of Mah Jong, simplified down and made into a card game anyone could play. JMhing is a Client/Server based Java program that requires command line commands to get the server going.

Sigh.

By default the Jar runs the client. The creator should have taken some tips from the quite well done Java version of Settlers of Catan (JSettlers) and had the startup screen allow the creation of a server to connect to.

Worse still, JMhing looks hideous. The graphics are like something some remedial primary school kids would draw in crayon

Reply #11 Posted: January 03, 2013, 11:43:51 am
I am now banned from GetSome

Offline Tiwaking!

  • Hero Member
  • Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!
  • Posts: 12,584
Quote from: oefox;1511794
When you say hard scoring do you mean remembering all the possible special hands? Quite like the proper game but takes a while if there's only one manual. Programming the AI would be interesting.
I just made an A.I for the Mah Jong game. Without putting a delay in, the games are incredibly quick.

And vicious

Code: [Select]
// import java.util.ArrayList;
import java.util.*;
import javax.swing.*;
import java.awt.*;
/**
This shouldnt be too hard
 * @author Tiwa
 * @version Thu Jan 03 15:16:19 NZDT 2013
 */
public class MahJongComputer{
// protected MahJongTable table;
public MahJongComputer(MahJongTable t){
// table=t;
}//con
/**Thu Jan 03 15:17:53 NZDT 2013
Lets try this. Discard is:
KEEP PAIRS
KEEP THREES
KEEP CHOWS
KEEP HONOUR
*/
public static Tile calculateDiscard(PlayerPanel panel){
Tile discard=null;
// MahJongButton discard=null;
// HashSet<Tile>singles=removeDuplicates(panel);
ArrayList<ArrayList<Tile>>singles=removeDuplicates(panel);
HashMap<String,ArrayList<Tile>>discards=getDiscards(panel.getTable());
ArrayList<Tile>candidates=new ArrayList<Tile>();
for(int i=0;i<singles.get(0).size();i++){
Tile test=singles.get(0).get(i);
String tname=test.toString();
ArrayList<Tile>discardedTiles=discards.get(tname);
if(discardedTiles!=null){
if(discardedTiles.size()>1)return test;
if(discardedTiles.size()==1)candidates.add(test);
}//fi not null
}//4
if(candidates.size()>0)discard=candidates.get(0);
if(discard==null && singles.get(0).size()>0)discard=singles.get(0).get(0);
else discard=singles.get(1).get(0);
return discard;
}//me
private static ArrayList<ArrayList<Tile>> removeDuplicates(PlayerPanel panel){
ArrayList<Tile>hand=panel.getPlayer().getHand().getHand();
ArrayList<ArrayList<Tile>>singles=new ArrayList<ArrayList<Tile>>();
singles.add(new ArrayList<Tile>());
singles.add(new ArrayList<Tile>());
HashMap<String,ArrayList<Tile>>map=new HashMap<String,ArrayList<Tile>>();
for(int i=0;i<hand.size();i++){
if(map.get(hand.get(i).toString())==null)map.put(hand.get(i).toString(),new ArrayList<Tile>());
map.get(hand.get(i).toString()).add(hand.get(i));
}//4
for (Map.Entry<String, ArrayList<Tile>>entry : map.entrySet()) {
ArrayList<Tile>sets=entry.getValue();
if(sets.size()==1)singles.get(0).add(sets.get(0));
if(sets.size()==1)singles.get(1).add(sets.get(0));
}//4 map
return singles;
}//me
private static HashMap<String,ArrayList<Tile>> getDiscards(MahJongTable table){
JPanel discards=table.getDiscards();
HashMap<String,ArrayList<Tile>>map=new HashMap<String,ArrayList<Tile>>();
Component[]comp=discards.getComponents();
for(int i=0;i<comp.length;i++){
Component c=comp[i];
if(c instanceof MahJongButton){
MahJongButton btn=(MahJongButton)c;
Tile tile=btn.getTile();
if(map.get(tile.toString())==null)map.put(tile.toString(),new ArrayList<Tile>());
map.get(tile.toString()).add(tile);
}//fi
}//4
return map;
}//me
} // class MahJongComputer
edit: Shit. The A.I is better at Mah Jong than I am!! >:|
Last Edit: January 03, 2013, 05:41:52 pm by Tiwaking!

Reply #12 Posted: January 03, 2013, 04:46:04 pm
I am now banned from GetSome

Offline Tiwaking!

  • Hero Member
  • Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!
  • Posts: 12,584
http://tiwaking.hostzi.com/mahjong/mahjong.html

Get it while it is hot. And barely functioning.


Just kidding. There are two bugs in it:

Occasionally you will have a turn skipped after a game reset. Has something to do with where  a player goes Mah Jong (Drawn Mah Jong 'continues' the game)
This is because I dont know what I am doing.

The other bug has to do with Chows and is apparently inherent to the MahJong programming scene.
This bug should occur because I have disabled chows.


Have fun!

Reply #13 Posted: January 04, 2013, 02:55:03 pm
I am now banned from GetSome

Offline Tiwaking!

  • Hero Member
  • Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!
  • Posts: 12,584
Quote from: Tiwaking!;1513478
There are two bugs in it:

Occasionally you will have a turn skipped after a game reset. Has something to do with where  a player goes Mah Jong (Drawn Mah Jong 'continues' the game)
This is because I dont know what I am doing.

I found out why this happens.

If you do not win a round the game resets, but it begins from the winners turn. Since it waits until it is your turn again, it 'skips' your first turn.

This means the post-losing game is played with 14 tiles instead of the customary 13 and the game gets incredibly vicious.

I think I will keep that as an option in the game when it gets fixed. I'll keep it in for now as it livens up the game when you get three dead hands in a row.

It is way more fun that the dumb 'goulash' rule the British use.
Quote from: Tiwaking!;1513478

The other bug has to do with Chows and is apparently inherent to the MahJong programming scene.
This bug shouldn't occur because I have disabled chows.

Reply #14 Posted: January 06, 2013, 12:04:09 pm
I am now banned from GetSome

Offline Tiwaking!

  • Hero Member
  • Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!
  • Posts: 12,584
Quote from: Tiwaking!;1513674
If you do not win a round the game resets, but it begins from the winners turn. Since it waits until it is your turn again, it 'skips' your first turn.

This bug is fixed now, but the side effect is that the computer is almost invincible.


Got to take the good with the bad I suppose.

Reply #15 Posted: January 16, 2013, 09:34:28 am
I am now banned from GetSome

Offline Tiwaking!

  • Hero Member
  • Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!
  • Posts: 12,584
Quote from: Tiwaking!;1514840
This bug is fixed now, but the side effect is that the computer is almost invincible.


Got to take the good with the bad I suppose.

I was wondering if anyone had actually played this game. Then I checked Google Analytics


242 people have tried this game since January 10th (When Analytics Policy changed)

Woah. That is crazy

Reply #16 Posted: January 17, 2013, 10:55:44 pm
I am now banned from GetSome