create_database.py 8.0 KB

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