create_database.py 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #!/usr/bin/env python
  2. """
  3. Database initialization for Carcassonne score keeping system.
  4. Copyright 2018 George C. Privon
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. """
  16. import sqlite3
  17. conn = sqlite3.connect('CarcassonneScore.db')
  18. c = conn.cursor()
  19. # player table
  20. c.execute('''CREATE TABLE players (playerID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  21. name TEXT NOT NULL DEFAULT "")''')
  22. # player names
  23. c.execute('''INSERT INTO players values (0,
  24. "John Smith")''')
  25. c.execute('''INSERT INTO players values (1,
  26. "Jane Doe")''')
  27. # games table
  28. # gameID - unique ID
  29. # location - free text
  30. # starttime - timecode
  31. # endtime - timecode
  32. # expansions - comma-separated list of expansions used (by expansionID)
  33. c.execute('''CREATE TABLE games (gameID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  34. location TEXT NOT NULL DEFAULT "",
  35. starttime TEXT NOT NULL DEFAULT "",
  36. endtime TEXT NOT NULL DEFAULT "",
  37. expansions TEXT NOT NULL DEFAULT "")''')
  38. # turns table
  39. # gameID - corresponds to games table
  40. # turnNum - incremented turn number (corresponds to a tile placement)
  41. # time - time at which the placement was made
  42. # builder - 0 if tile was placed as part of normal turn, 1 if placed
  43. # as a result of a builder token
  44. # playerID - player who made the turn
  45. c.execute('''CREATE TABLE turns (gameID INTEGER NOT NULL,
  46. turnNum INTEGER NOT NULL,
  47. time TEXT NOT NULL,
  48. builder INTEGER NOT NULL,
  49. playerID INTEGER NOT NULL)''')
  50. # individual scores
  51. # gameID - unique per game
  52. # playerID - corresponds to entry from players table
  53. # turnNum - turn number (corresponds to number in turns table)
  54. # scoreID - ID number for the score (unique to game?)
  55. # ingame - 1 if scored during regular play, 0 if scored after tiles are gone
  56. # points - number of points awarded
  57. # scoretype - road, city, meadow, etc.
  58. # sharedscore - was this score shared with another player?
  59. # token - token(s) used for score (e.g., meeple, wagon, pig)
  60. # extras - any other items (e.g., trade goods)
  61. # comments - text annotation
  62. c.execute('''CREATE TABLE scores (gameID INTEGER NOT NULL,
  63. playerID INTEGER NOT NULL,
  64. turnNum INTEGER NOT NULL,
  65. scoreID INTEGER NOT NULL,
  66. ingame INTEGER NOT NULL,
  67. points INTEGER NOT NULL,
  68. scoretype TEXT NOT NULL,
  69. sharedscore INTEGER NOT NULL,
  70. token TEXT NOT NULL,
  71. extras NOT NULL,
  72. comments TEXT)''')
  73. # list of expansions
  74. # mini - 1 if a mini expanion, otherwise 0
  75. # active - 1 if it can be played, otherwise 0
  76. # tokens - additional tokens provided beyond the base game
  77. # scoretypes - additional classes of scoring enabled
  78. # Ntiles - number of tiles added
  79. # tiletypes - special scorable tiles added
  80. c.execute('''CREATE TABLE expansions (expansionID INTEGER PRIMARY KEY,
  81. name TEXT NOT NULL,
  82. mini INTEGER,
  83. active INTEGER,
  84. tokens TEXT,
  85. scoretypes TEXT,
  86. Ntiles INTEGER,
  87. tiletypes TEXT)''')
  88. # large expansions
  89. # taken from http://carcassonne.wikia.com/wiki/Official_expansions
  90. # Only 1, 2, and 5 are currently populated
  91. c.execute('''INSERT INTO expansions values (1,
  92. "Inns & Cathedrals",
  93. 0,
  94. 1,
  95. "BigMeeple",
  96. "",
  97. 18,
  98. "Cathedral,InnonLake")''')
  99. c.execute('''INSERT INTO expansions values (2,
  100. "Traders & Builders",
  101. 0,
  102. 1,
  103. "Pig,Builder",
  104. "",
  105. 24,
  106. "TradeGoods")''')
  107. c.execute('''INSERT INTO expansions values (3,
  108. "Princess & Dragon",
  109. 0,
  110. 0,
  111. "",
  112. "",
  113. 0,
  114. "")''')
  115. c.execute('''INSERT INTO expansions values (4,
  116. "The Tower",
  117. 0,
  118. 0,
  119. "",
  120. "",
  121. 0,
  122. "")''')
  123. c.execute('''INSERT INTO expansions values (5,
  124. "Abbey & Mayor",
  125. 0,
  126. 1,
  127. "Mayor,Wagon,Barn",
  128. "",
  129. 12,
  130. "Abbey")''')
  131. c.execute('''INSERT INTO expansions values (6,
  132. "Count, King & Robber",
  133. 0,
  134. 0,
  135. "",
  136. "",
  137. 0,
  138. "")''')
  139. c.execute('''INSERT INTO expansions values (7,
  140. "The Catapult",
  141. 0,
  142. 0,
  143. "",
  144. "",
  145. 0,
  146. "")''')
  147. c.execute('''INSERT INTO expansions values (8,
  148. "Bridges, Castles & Bazaars",
  149. 0,
  150. 0,
  151. "",
  152. "",
  153. 0,
  154. "")''')
  155. c.execute('''INSERT INTO expansions values (9,
  156. "Hills & Sheep",
  157. 0,
  158. 0,
  159. "",
  160. "",
  161. 0,
  162. "")''')
  163. c.execute('''INSERT INTO expansions values (10,
  164. "Under the Big Top",
  165. 0,
  166. 0,
  167. "",
  168. "",
  169. 0,
  170. "")''')
  171. #mini expansions
  172. c.execute('''INSERT INTO expansions values(101,
  173. "The River",
  174. 1,
  175. 1,
  176. "",
  177. "",
  178. 12,
  179. "")''')
  180. c.execute('''INSERT INTO expansions values(102,
  181. "The Abbott",
  182. 1,
  183. 1,
  184. "Abbott",
  185. "Garden",
  186. 0,
  187. "")''')
  188. conn.commit()
  189. conn.close()