본문 바로가기
푸로젝트/마작

3.1 화료 - 필수적인 게임의 진행 과정의 구현

by 눕는게최고야 2023. 9. 22.

구현 기능 목록

1. 마작게임의 뼈대를 구현 : )

2. 유효패를 계산하여 가장 효율적인 조패를 계산

2-1. 유효패에 대한 개념 정하기

2-2. 패의 샨텐을 계산하는 기능 구현

2-3 각 카드의 유효패를 계산하여 가장 효율적인 타패를 찾음

3. 화료 

3.1 필수적인 게임의 진행 과정의 구현

4. 타가들의 버림 배를 구현. 

5. 다른 여러 기능을 구현. (리치 퐁 깡 등)

6. 1인 마작 게임 구현. 


 

Class  
Card String type int number int idCode
Deck List<Card> cards int[ ] [ ]
cardInformation
 
Game Deck deck    
User List<Card> east_hand 샨텐 계산 Methods 화료

구현 클래스 정리.

3. 화료

3개의 블록으로 이루어진 4개의 몸통과, 2개의 같은 패로 이루어진 1개의 머리 (특수 조건 제외 ex 치또이쯔 , 국사무쌍)

 

서론

들어가기에 앞서, 화료가 되기 전의 상태를 생각해 보았다. 울기(후로)를 제외하고 생각했을 때, 패의 카드가 들어오고 나가는 것의 반복을 통해 화료에 가까워질 것이다.

그렇다면 화료에 대한 조건, 상태를 구현하기 전 패의 카드의 들어옴과 나감에 대해 실제 게임과 같은 형태를 구현하는 것이 선행이 되어야 한다.

 

구현계획 

1. 무엇을 구현할 것인가 

게임의 진행 (패의 카드의 들어옴과 나감)

 

2. 어떻게 구현할 것인가

Game 내 User에게 패를 주고, User는 패를 버리고 이를 반복.. 그중 User가 어떤 신호를 보내면 이를 중단. 

 

3. 어디에 구현힐 것인가

Contorller에 구현(Main) 

각 클래스들을 MVC 모델에 맞게 리팩토링.

 

결괏값 예시를 작성하여 출력에 관한 기능도 추가.

게임시작

당신의 패 : ~~

쯔모 : ~ 당신의 패 : ~~~

버릴카드를 선택해주세요.(추천 버림패 : ~)

(반복)

텐파이! 

화료했습니다. 점수 : 48000점 

 

구현과정

1. 결괏값을 바탕으로 outputView 클래스를 구현. 

package view;

public class OutView {
    public void printGameStartMessage(){
        System.out.println("게임시작!");
    }
    //TODO model.User 클래스 패 출력 메소드 구현
    public void printHand(String string){
        System.out.println("당신의 패 : "+string);
    }
    public void printDraw(String string){
        System.out.print("쯔모 : "+string);
    }
    public void printRequestAbandonCard(String string){
        System.out.println("버림패를 선택해 주세요. (추천 버림패 "+string+")" );
    }
    public void printAlreadyGame(){
        System.out.println("텐파이!");
    }
    public void printScore(int score){
        System.out.println(score+"점!!");
    }
}

 

2. 클래스 리팩토링

 리팩토링 과정에서 접근제어자에 대한 공부를 다시 하게 되었다. 

 

3. inputView 클래스의 구현.

package view;

import java.util.*;
public class InputView {
    public String raedLine(){
        Scanner sc = new Scanner(System.in);
        return sc.nextLine();
    }
    public int readInt(){
        Scanner sc = new Scanner(System.in);
        return sc.nextInt();
    }
}

 

너무.. 뭐랄까 멍청하게 구현해서 다음에 손을 볼 계획..

 

4. Main클래스에 전체적인 기능  정리

import model.MahjongGame;
import view.OutView;
import view.InputView;

public class Main {
    static OutView outView = new OutView();
    static InputView inputView =new InputView();
    public static void main(String[] args) {
        MahjongGame game = new MahjongGame();
        outView.printGameStartMessage();
        outView.printHand(game.showMyHands(0));
        while(true){
            outView.printDraw(game.nextStep().toString());
            outView.printHand(game.showMyHands(0));
            outView.printRequestAbandonCard(game.getUser(0).findUnnecessaryCard().toString());
            game.getUser(0).abandonCard(inputView.readInt());
            if(game.getUser(0).makeHand()){
                break;
            }
        }
    }
}

한 명의 사용자의 마작의 조패 시뮬레이션 구현

 

마치며

조패알고리즘 업그레이드의 필요.

지금 구현한 조패 알고리즘이 이상한 것을 눈치챘다. ㅠㅠ 생각해 보기

 

기능을 추가하기 전 무엇을 어떻게 어디에 구현할 것인가? 에 대한 질문

클래스를  구현할 때, 가장 많이 고민되는 질문들을 나름의 공식화를 시켜보았다. 물론 나중에 수정될 지도..

 

  Class   

m
o
d
e
l

Card String type int number int idCode
Deck List<Card> cards int[ ] [ ]
cardInformation
 
Game Deck deck    
Us
er
List<Card> east_hand 샨텐 계산 Methods 화료
v
i
e
w
inputView
outputView
con
torller
Main