LoginSignup
1
2

More than 5 years have passed since last update.

トランプゲーム(未完)

Last updated at Posted at 2017-09-20

能書き

トランプ大統領の国連演説が良かったので、トランプゲームを作ろうと思いました。

しかし、眠いので途中まで。

実行結果 ポーカーゲーム

手札交換無し、判定は目視で。
本当はアメリカン・ページワンを作りたかったので、またそのうち。

  heart    4    club     Q
  club     5    heart    5
  club     6    club     4
  diamond  3    spade    J
  club     7    spade    6
 続行するには何かキーを押してください . . .

ソースプログラム

半分に割って、交互に並べるきり方の、逆過程をやったのですが、

        deck = [deck(::2), deck(2::2)]  

全くきれずに団子になるので、任意の場所で割って乗せるきり方を加えました。

    module m_cards
      implicit none
      character(len = *), parameter :: mark(*) = ['club', 'diamond', 'heart', 'spade']
      character(len = 2), parameter :: num (*) = [' A', ' 2', ' 3', ' 4', ' 5', ' 6', ' 7', ' 8' ,' 9', '10', ' J', ' Q', ' K']
      enum, bind(c) 
        enumerator :: club, diamond, heart, spade
        enumerator :: ace,  jack = 11, queen, king
      end enum

      integer, parameter :: noc = 52, ns = 4, nc = noc / ns      
      type :: t_card
        character(len = len(mark(1))) :: mark 
        character(len = 2) :: num
      end type    
    contains
      type(t_card) function to_card(i) 
        integer, intent(in) :: i
        to_card = t_card( mark((i - 1) / nc + 1), num(nc + modulo(i, -nc)) )
      end function to_card
    end module m_cards

    program Console2
      use m_cards
      implicit none
      type (t_card) :: hands(5, 2)
      integer :: i, j, k, n, deck(52)
      real :: r
      forall (i = 1:noc) deck(i) = i   ! [1:noc]
      call random_seed()
      call random_number(r)
      n = 10 + int(200 * r)
      ! shuffle
      do i = 1, n
        deck = [deck(2::2), deck(::2)]    
        call random_number(r)
        n = int(noc * r) + 1
        deck = [deck(n:), deck(:n - 1)]
      end do
      ! deal
      k = 0 
      do i = 1, size(hands, 1)
        do j = 1, size(hands, 2)
          k = k + 1 
          hands(i, j) = to_card(deck(k))  
        end do    
      end do
      ! print 
      do i = 1, 5
        print "(2(a8, ' ', a, '   '))", hands(i, :)
      end do 
    end program Console2
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2