create_database.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. # IPython log file
  2. import sqlite3
  3. conn = sqlite3.connect('CarcassonneScore.db')
  4. c = conn.cursor()
  5. # player table
  6. c.execute('''CREATE TABLE players (playerID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  7. name TEXT NOT NULL DEFAULT "")''')
  8. # player names
  9. c.execute('''INSERT INTO players values (0,
  10. "John Smith")''')
  11. # games table
  12. # gameID - unique ID
  13. # location - free text
  14. # starttime - timecode
  15. # endtime - timecode
  16. # expansions - comma-separated list of expansions used (by expansionID)
  17. c.execute('''CREATE TABLE games (gameID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  18. location TEXT NOT NULL DEFAULT "",
  19. starttime TEXT NOT NULL DEFAULT "",
  20. endtime TEXT NOT NULL DEFAULT "",
  21. expansions TEXT NOT NULL DEFAULT "")''')
  22. # turns table
  23. # gameID - corresponds to games table
  24. # turnNum - incremented turn number (corresponds to a tile placement)
  25. # time - time at which the placement was made
  26. # builder - 0 if tile was placed as part of normal turn, 1 if placed
  27. # as a result of a builder token
  28. # playerID - player who made the turn
  29. c.execute('''CREATE TABLE turns (gameID INTEGER NOT NULL,
  30. turnNum INTEGER NOT NULL,
  31. time TEXT NOT NULL,
  32. builder INTEGER NOT NULL,
  33. playerID INTEGER NOT NULL)''')
  34. # individual scores
  35. # gameID - unique per game
  36. # playerID - corresponds to entry from players table
  37. # turnNum - turn number (corresponds to number in turns table)
  38. # scoreID - ID number for the score (unique to table or to game?)
  39. # ingame - 1 if scored during regular play, 0 if scored after tiles are gone
  40. # points - number of points awarded
  41. # scoretype - road, city, meadow, etc.
  42. # token - token(s) used for score (e.g., meeple, wagon, pig)
  43. # extras - any other items (e.g., trade goods)
  44. # comments - text annotation
  45. c.execute('''CREATE TABLE scores (gameID INTEGER NOT NULL,
  46. playerID INTEGER NOT NULL,
  47. turnNum INTEGER NOT NULL,
  48. scoreID INTEGER NOT NULL,
  49. ingame INTEGER NOT NULL,
  50. points INTEGER NOT NULL,
  51. scoretype TEXT NOT NULL,
  52. sharedscore INTEGER NOT NULL,
  53. token TEXT NOT NULL,
  54. extras NOT NULL,
  55. comments TEXT)''')
  56. # list of expansions
  57. # mini - 1 if a mini expanion, otherwise 0
  58. # active - 1 if it can be played, otherwise 0
  59. # tokens - additional tokens provided beyond the base game
  60. # Ntiles - number of tiles added
  61. # tiletypes - special scorable tiles added
  62. c.execute('''CREATE TABLE expansions (expansionID INTEGER PRIMARY KEY,
  63. name TEXT NOT NULL,
  64. mini INTEGER,
  65. active INTEGER,
  66. tokens TEXT,
  67. Ntiles INTEGER,
  68. tiletypes TEXT)''')
  69. # large expansions
  70. # taken from http://carcassonne.wikia.com/wiki/Official_expansions
  71. # Only 1, 2, and 5 are currently populated
  72. c.execute('''INSERT INTO expansions values (1,
  73. "Inns & Cathedrals",
  74. 0,
  75. 1,
  76. "BigMeeple",
  77. 18,
  78. "Cathedral,InnonLake")''')
  79. c.execute('''INSERT INTO expansions values (2,
  80. "Traders & Builders",
  81. 0,
  82. 1,
  83. "Pig,Builder",
  84. 24,
  85. "TradeGoods")''')
  86. c.execute('''INSERT INTO expansions values (3,
  87. "Princess & Dragon",
  88. 0,
  89. 0,
  90. "",
  91. 0,
  92. "")''')
  93. c.execute('''INSERT INTO expansions values (4,
  94. "The Tower",
  95. 0,
  96. 0,
  97. "",
  98. 0,
  99. "")''')
  100. c.execute('''INSERT INTO expansions values (5,
  101. "Abbey & Mayor",
  102. 0,
  103. 1,
  104. "Mayor,Wagon,Barn",
  105. 12,
  106. "Abbey")''')
  107. c.execute('''INSERT INTO expansions values (6,
  108. "Count, King & Robber",
  109. 0,
  110. 0,
  111. "",
  112. 0,
  113. "")''')
  114. c.execute('''INSERT INTO expansions values (7,
  115. "The Catapult",
  116. 0,
  117. 0,
  118. "",
  119. 0,
  120. "")''')
  121. c.execute('''INSERT INTO expansions values (8,
  122. "Bridges, Castles & Bazaars",
  123. 0,
  124. 0,
  125. "",
  126. 0,
  127. "")''')
  128. c.execute('''INSERT INTO expansions values (9,
  129. "Hills & Sheep",
  130. 0,
  131. 0,
  132. "",
  133. 0,
  134. "")''')
  135. c.execute('''INSERT INTO expansions values (10,
  136. "Under the Big Top",
  137. 0,
  138. 0,
  139. "",
  140. 0,
  141. "")''')
  142. #mini expansions
  143. c.execute('''INSERT INTO expansions values(101,
  144. "The River",
  145. 1,
  146. 1,
  147. "",
  148. 12,
  149. "")''')
  150. conn.commit()
  151. conn.close()