Example #1
0
    def __init__(self, host, port):
        #self.board = TTTBoard()
        self.my_moves = []
        self.opponent_moves = []
        self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        print_debug('Socket attempting to connect to host {}, port {}'.format(
            host, port))
        connected = False
        while not connected:
            try:
                self._sock.connect((host, port))
                connected = True
            except ConnectionRefusedError:
                print_debug('connection was refused...')
                time.sleep(0.5)
        print('connected to socket, waiting for second player')
        message = get_block(self._sock)
        while message != b'StartGame':
            message = get_block(self._sock)
            print_debug(message)

        #next message is X or O
        x_or_o = get_block(self._sock)
        if x_or_o not in {b'X', b'O'}:
            print_debug(
                'Cannot play game - was not given a value. Was given {}'.
                format(x_or_o))
        else:
            self.value = x_or_o
            self.board_value = 2 if self.value == b'O' else 1
            print_debug('Value for user: '******'Client has connected and been assigned socket name',
                    self._sock.getsockname())
Example #2
0
    def take_turn(self, user):
        user_sock = user[0]
        print_debug('Waiting for user {} to move'.format(user[1]))
        user_turn = get_block(user_sock)
        #check to make sure user hasn't exited
        if user_turn == b'Exiting':
            print_debug('User {} has left the game'.format(user[1]))
            put_block(
                list(filter(lambda x: x[0] != user_sock, self.users))[0],
                b'Exiting')
            self.close()
        else:
            print_debug('Attempting to take turn {}'.format(
                user_turn.decode()))
            try:
                user_turn = int(user_turn.decode())
                if not self.board.make_move(user_turn, user[1]):
                    #put_block(user_sock, b'Invalid move.')
                    self.take_turn(user)
                else:
                    print_debug(user[1], ' chose square ', user_turn)
                    print_debug('Board: ')
                    print_debug(self.board.get_printable_board())
                    other_user = list(filter(lambda x: x != user,
                                             self.users))[0][0]
                    put_block(other_user, str(user_turn).encode('ascii'))

            except ValueError:
                print_debug('could not convert int to value')
	def get_tender_place(self):
		if(1 == int(self.keishu_cd)):
			start = u'<td>入札場所<br></td> <td>'
		elif(2 == int(self.keishu_cd)):
			start = u'<tr> <td>見積書受付場所<br></td> <td>'
		stop = u'</td> </tr>'
		tender_place = util.get_block(self.html, start, stop)
		return tender_place
	def get_anken_open_date(self):
		if(1 == int(self.keishu_cd)):
			start = u'<td>公開開始日時<br></td> <td>'
		elif(2 == int(self.keishu_cd)):
			start = u'<tr> <td>公開開始日時<br>(=見積書受付開始)<br></td> <td>'
		stop = u'</td> </tr>'
		anken_open_date = util.get_block(self.html, start, stop)
		anken_open_date = self.format_date(anken_open_date)
		return anken_open_date
	def get_price(self):
		start = u'<tr> <td>落札金額(税込・円)</td><td>'
		stop = u'</td> </tr>'
		price = util.get_block(self.html, start, stop)

		if(None != price):
			price = re.sub('&nbsp;', '', price)

		return price
	def get_tender_date(self):
		if(1 == int(self.keishu_cd)):
			start = u'<tr> <td>入札日時<br></td> <td>'
		elif(2 == int(self.keishu_cd)):
			start = u' <tr> <td>見積書〆切日時<br></td> <td>'

		stop = u'</td> </tr>'
		tender_date = util.get_block(self.html, start, stop)
		tender_date = self.format_date(tender_date)
		return tender_date
	def format_date(self, date_string):
		if(date_string is None):
			return date_string
		date_string_f = ''

		year_j = util.get_block(date_string, u'', u'年')
		month = util.get_block(date_string , u'年', u'月')
		day = util.get_block(date_string , u'月', u'日')
		hour = util.get_block(date_string , u'日', u'時')
		minute = util.get_block(date_string , u'時', u'分')

		year_ad = util.convert_J2AD(year_j)

		if(hour is None):
			date_string_f = '/'.join([year_ad, month, day])
		else:
			date_string_f = '/'.join([year_ad, month, day]) + ' ' + ':'.join([hour, minute])

		return date_string_f
	def get_attached_file_1(self):
		start = u'<tr> <td>添付ファイル1</td><td> <a href="'
		stop = u'">'
		attached_file_1 = util.get_block(self.html, start, stop)
		# print(attached_file_1)
		if attached_file_1 is not None:
			attached_file_1 = self.site_url + attached_file_1
		else:
			attached_file_1 = ''
		# print(attached_file_1)
		return attached_file_1;
	def get_attached_file_2(self):
		start = u'<tr> <td>添付ファイル2</td><td> <a href="'
		stop = u'">'
		attached_file_2 = util.get_block(self.html, start, stop)
		# print(attached_file_2)
		if attached_file_2 is not None:
			attached_file_2 = self.site_url + attached_file_2
		else:
			attached_file_2 = ''
		# print(attached_file_2)
		return attached_file_2;
	def get_attached_file_3(self):
		start = u'<tr> <td>添付ファイル3</td><td> <a href="'
		stop = u'">'
		attached_file_3 = util.get_block(self.html, start, stop)
		# print(attached_file_3)
		if attached_file_3 is not None:
			attached_file_3 = self.site_url + attached_file_3
		else:
			attached_file_3 = ''
		# print(attached_file_3)
		return attached_file_3;
Example #11
0
 def other_player_turn(self):
     print_debug('Waiting for player {} to move'.format('X' if self.value ==
                                                        b'O' else 'O'))
     # server sends board representation
     #check if move data has already been sent
     move = get_block(self._sock)
     if move == b'Exiting':
         print_debug('Other user has left the game')
         self.close()
     else:
         try:
             move = int(move)
         except ValueError:
             print_debug('Didnt get a valid integer from the server')
         self.TTTPlayer_me.make_move(move,
                                     b'X' if self.value == b'O' else b'O')
         #self.board.make_move(move, b'X' if self.value == b'O' else b'O')
         self.opponent_moves.append(move)
         print_debug(self.TTTPlayer_me.board().get_printable_board())
         if self.TTTPlayer_me.board().detect_winner():
             return 1
         elif self.TTTPlayer_me.board().detect_draw():
             return 2
	def get_gyoumu_kbn_2(self):
		start = u'<tr> <td>業務小分類</td> <td>'
		stop = u'</td> </tr>'
		gyoumu_kbn_2 = util.get_block(self.html, start, stop)
		return gyoumu_kbn_2
	def get_anken_name(self):
		start = u'<tr> <td>案件名(事業年度・名称)</td> <td>'
		stop = u'</td> </tr>'
		anken_name = util.get_block(self.html, start, stop)
		return anken_name
	def get_anken_no(self):
		start = u'<tr> <td width="200">案件番号</td> <td>'
		stop = u'</td> </tr>'
		anken_no = util.get_block(self.html, start, stop)
		return anken_no
	def get_company_area(self):
		start = u'<tr> <td>対象業者の地域要件</td> <td>'
		stop = u'</td> </tr>'
		company_area = util.get_block(self.html, start, stop)
		return company_area
	def get_keishu_name(self):
		start = u'<tr> <td>契約種別</td> <td>'
		stop = u'</td> </tr>'
		keishu_name = util.get_block(self.html, start, stop)
		keishu_name = re.sub('<!--.*-->\s*', '', keishu_name)
		return keishu_name
	def get_result_close_date(self):
		start = u'<tr> <td>結果表示終了日時</td> <td>'
		stop = u'</td> </tr>'
		result_close_date = util.get_block(self.html, start, stop)
		result_close_date = self.format_date(result_close_date)
		return result_close_date
	def get_raku_name(self):
		start = u'<tr> <td>落札業者名等</td><td>'
		stop = u'</td> </tr>'
		raku_name = util.get_block(self.html, start, stop)
		return raku_name
	def get_result_open_date(self):
		start = u'<tr> <td width="200">結果表示開始日時</td> <td>'
		stop = u'</option> </td> </tr>'
		result_open_date = util.get_block(self.html, start, stop)
		result_open_date = self.format_date(result_open_date)
		return result_open_date
	def get_notes(self):
		start = u'<tr> <td>特記事項</td><td>'
		stop = u'</td> </tr>'
		notes = util.get_block(self.html, start, stop)
		return notes
	def get_tanto_name(self):
		# start = u'<tr> <td>担当者名・電話番号</td><td>'
		start = u'<tr> <td>問い合わせ先<br>(担当者名・電話番号)</td><td>'
		stop = '</td> </tr>'
		tanto_name = util.get_block(self.html, start, stop)
		return tanto_name
	def get_anken_close_date(self):
		start = u'<tr> <td>公開終了日時</td> <td>'
		stop = u'</td> </tr>'
		anken_close_date = util.get_block(self.html, start, stop)
		anken_close_date = self.format_date(anken_close_date)
		return anken_close_date
	def get_limit_date(self):
		start = u'<tr> <td>履行期限</td> <td>'
		stop = u'</td> </tr>'
		limit_date = util.get_block(self.html, start, stop)
		limit_date = self.format_date(limit_date)
		return limit_date
	def get_kasitu_name(self):
		start = u'<tr> <td>実施機関</td> <td>'
		stop = u'</td> </tr>'
		kasitu_name = util.get_block(self.html, start, stop)
		return kasitu_name
Example #25
0
def get_model(nc):
    batchnormalization = nc.get('batchnormalization', False)
    dropout1 = nc.get('dropout', 0)
    dropout2 = nc.get('dropout2', 0)
    pooling = nc.get('pooling', 'max')
    use_stats = nc.get('use_stats', False)

    inputs = Input(shape=util.INPUT_SHAPE, name='image_input')

    x0 = Conv2D(32, (7, 7),
                kernel_initializer='glorot_uniform',
                strides=(2, 2),
                padding='same',
                name='conv1')(inputs)
    x0 = util.CReLU()(x0)
    x0 = Dropout(dropout1)(x0)

    x = util.get_block(inputs,
                       nc,
                       batchnormalization,
                       nb_filter1=32,
                       nb_filter2=32,
                       dropout1=dropout1,
                       dropout2=dropout1,
                       pooling=0,
                       kernel_size1=7)
    if pooling == 'max':
        x = MaxPooling2D(pool_size=(2, 2))(x)
    elif pooling == 'avg':
        x = AveragePooling2D(pool_size=(2, 2))(x)
    x = Concatenate(axis=-1)([x, x0])

    if nc.get('use_conv_layer'):
        x = util.conv_block(3, [8, 16, 8],
                            weight_decay=0.,
                            stride=1,
                            batch_momentum=0.99,
                            batchnormalization=batchnormalization)(x)
        if pooling == 'max':
            x = MaxPooling2D(pool_size=(2, 2))(x)
        elif pooling == 'avg':
            x = AveragePooling2D(pool_size=(2, 2))(x)

    x = util.get_block(x, nc, batchnormalization, 32, 0, dropout1, dropout2,
                       pooling)
    if nc.get('use_conv_layer'):
        x = util.conv_block(3, [8, 16, 8],
                            weight_decay=0.,
                            stride=1,
                            batch_momentum=0.99,
                            batchnormalization=batchnormalization)(x)
        if pooling == 'max':
            x = MaxPooling2D(pool_size=(2, 2))(x)
        elif pooling == 'avg':
            x = AveragePooling2D(pool_size=(2, 2))(x)
    x = util.get_block(x, nc, batchnormalization, 32, 0, dropout1, dropout2,
                       pooling)

    if pooling == 'max':
        x = MaxPooling2D(pool_size=(2, 2))(x)
    elif pooling == 'avg':
        x = AveragePooling2D(pool_size=(2, 2))(x)

    x = Flatten()(x)
    x = Dropout(dropout1)(x)
    x = Dense(512, activation='relu')(x)
    x = Dropout(dropout1)(x)
    x = Dense(128, activation='relu')(x)

    if use_stats:
        inputs2 = Input(shape=(278, ), name='image_input2')
        x2 = Dense(256, activation='relu')(inputs2)
        x2 = Dense(128, activation='sigmoid')(x2)
        x = concatenate([x, x2], axis=1)
        x = Dense(128, activation='relu')(x)
        x = Dropout(dropout1)(x)
        x = Dense(17, activation='sigmoid')(x)
        model = Model(inputs=[inputs, inputs2], outputs=x)
    else:
        x = Dropout(dropout1)(x)
        x = Dense(17, activation='sigmoid')(x)
        model = Model(inputs=inputs, outputs=x)
    model.compile(loss=nc.get('loss'),
                  optimizer=nc.get('optimizer'),
                  metrics=nc.get('metrics'))
    print(model.summary())
    return model